A Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML code in a more accessible method.
Project description
Emojificate is a Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML code in a more accessible method.
Usage
To convert a string from the command line:
$ python3 -m emojificate "I 💜 emoji 😊" I <img src="https://twemoji.maxcdn.com/36x36/1f49c.png" alt="💜" title="Purple Heart" aria-label="Emoji: Purple Heart"> emoji <img src="https://twemoji.maxcdn.com/36x36/1f60a.png" alt="😊" title="Smiling Face With Smiling Eyes" aria-label="Emoji: Smiling Face With Smiling Eyes">
Or, if you’ve got a Django project, put emojificate into your INSTALLED_APPS, and then use the following in a template:
{% load emojificate %} This is some {{ user_content|emojificate }} that has emoji in it. {% emojified %} This is some template content that 💜 emoji as well. {% endemojified %}
Implementation
TL;DR: Take a string, split it into token, and if a token is emoji, process it into a nice format.
Splitting the string is a problem, because at the moment it does not handle Zero Width Joining sequences. However, native Python string tokenization does work for the most part.
Given a list of tokens, we can leverage the native unicodedata to:
see if a token is a unicode Symbol (an emoji)
get the codepoint for the emoji, and
get the name of the emoji
From there, we construct an <img> replacement for the emoji:
Use images from twemoji, Twitter’s emoji set
Have an alt parameter containing the original emoji. This allows for copying-pasting.
Use the name of the emoji in the title parameter. This allows for hover-tooltips.
Add an aria-label for screen-reader accessibility.
For more information, see Solve For Emoji.
Limitations
Does not handle Zero Width Join Sequences; for example: 🖐🏽, 👩👩👧
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for emojificate-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbfdd1031641d7f472a6650983d7e04464f18c56fa13adb48ed1108ff96ef7b9 |
|
MD5 | d55a96dd1b446f99fde5494eb333dbdf |
|
BLAKE2b-256 | 1f638c8d04ad4feebb568c271e44b927f2e9f7a244dbbccae65ea72312f3104a |