emojificate
===========
|status| |release| |date|
.. |status| image:: https://img.shields.io/github/actions/workflow/status/glasnt/emojificate/pytest.yml?branch=latest&label=pytest&style=flat-square :alt: GitHub Workflow Status
.. |release| image:: https://img.shields.io/github/v/release/glasnt/emojificate?sort=semver&style=flat-square :alt: GitHub release (latest SemVer)
.. |date| image:: https://img.shields.io/github/release-date/glasnt/emojificate?style=flat-square :alt: GitHub Release Date
Emojificate is a Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML, a more accessible method than browser defaults.
Installation
------------
emojificate is available on pypi::
pip install emojificate
Usage
-----
To convert a string from the command line::
$ python3 -m emojificate "I 💜 emoji 😊"
I
<img src="https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/1f49c.png"
css="emojificiate" alt="💜" title="Purple Heart"
aria-label="Emoji: Purple Heart">
emoji
<img src="https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/1f60a.png"
css="emojificiate" alt="😊" title="Smiling Face With Smiling Eyes"
aria-label="Emoji: Smiling Face With Smiling Eyes">
Change the class with ``--css-class`` (default "emojificate"). To get SVG instead of PNG, use ``--filetype svg``.
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 %}
Configure with ``EMOJIFICATE_FILETYPE`` and ``EMOJIFICIATE_CSS_CLASS`` in your ``settings.py``, and add some css to make the emoji not huge.
Implementation
--------------
TL;DR: Take a string, split it into tokens, and if a token is emoji, process it into a nice format.
As of 0.4.0, string-splitting is now handled by `grapheme <https://github.com/alvinlindstam/grapheme>`__.
Given a list of tokens, we can leverage the native `unicodedata <https://docs.python.org/3/library/unicodedata.html>`__ to:
* see if a token is a unicode Symbol (an emoji)
* get the codepoint for the emoji, and
* get the name of the emoji.
If a token is a grapheme and not a character, there won't be a record of what it is in unicodedata. In that case emojificate defaults to a human-readable version of the shortcode provided by `emoji <https://github.com/carpedm20/emoji>`__.
From there, we construct an ``<img>`` replacement for the emoji:
* Use images from `twemoji <https://github.com/twitter/twemoji>`__, Twitter's emoji set (if the URL exists)
* 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 <https://glasnt.com/blog/solve-for-emoji/>`__.
Implementation in other languages
---------------------------------
Ruby
~~~~~
.. code-block:: ruby
require 'gemoji'
def cdn
"https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/"
end
def emojificate(string)
string.split("").each do |s|
e = Emoji.find_by_unicode(s)
if e then
u = s.ord.to_s(16) # e.g. 1f431
d = e.description # e.g. "cat face"
img = "<img src=\"#{cdn}/#{u}.png\" alt=\"#{s}\" title=\"#{d}\" aria-label=\"Emoji: #{d}\">"
print img
else
print s
end
end
end
Raw data
{
"_id": null,
"home_page": "https://github.com/glasnt/emojificate",
"name": "emojificate",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "emoji accessibility a11y",
"author": "Katie McLaughlin",
"author_email": "katie@glasnt.com",
"download_url": "https://files.pythonhosted.org/packages/a6/41/e3ec5e859ace64102c3c3b8d868df7858b5a182c8aa389bc642842c5dd3f/emojificate-0.7.0.tar.gz",
"platform": null,
"description": "emojificate\n===========\n\n|status| |release| |date|\n \n.. |status| image:: https://img.shields.io/github/actions/workflow/status/glasnt/emojificate/pytest.yml?branch=latest&label=pytest&style=flat-square :alt: GitHub Workflow Status\n\n.. |release| image:: https://img.shields.io/github/v/release/glasnt/emojificate?sort=semver&style=flat-square :alt: GitHub release (latest SemVer)\n\n.. |date| image:: https://img.shields.io/github/release-date/glasnt/emojificate?style=flat-square :alt: GitHub Release Date\n\nEmojificate is a Python implementation of a concept of using fallback images, alt text, title text and aria labels to represent emoji in HTML, a more accessible method than browser defaults. \n\nInstallation\n------------\n\nemojificate is available on pypi::\n\n pip install emojificate\n\nUsage\n-----\n\nTo convert a string from the command line::\n\n $ python3 -m emojificate \"I \ud83d\udc9c emoji \ud83d\ude0a\"\n I\n <img src=\"https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/1f49c.png\"\n css=\"emojificiate\" alt=\"\ud83d\udc9c\" title=\"Purple Heart\" \n aria-label=\"Emoji: Purple Heart\">\n emoji \n <img src=\"https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/1f60a.png\"\n css=\"emojificiate\" alt=\"\ud83d\ude0a\" title=\"Smiling Face With Smiling Eyes\"\n aria-label=\"Emoji: Smiling Face With Smiling Eyes\">\n\nChange the class with ``--css-class`` (default \"emojificate\"). To get SVG instead of PNG, use ``--filetype svg``.\n\n\nOr, if you've got a Django project, put ``emojificate`` into your ``INSTALLED_APPS``, and then use the following in a template::\n\n {% load emojificate %}\n This is some {{ user_content|emojificate }} that has emoji in it.\n\n {% emojified %}\n This is some template content that \ud83d\udc9c emoji as well.\n {% endemojified %}\n\nConfigure with ``EMOJIFICATE_FILETYPE`` and ``EMOJIFICIATE_CSS_CLASS`` in your ``settings.py``, and add some css to make the emoji not huge.\n\nImplementation\n--------------\n\nTL;DR: Take a string, split it into tokens, and if a token is emoji, process it into a nice format.\n\nAs of 0.4.0, string-splitting is now handled by `grapheme <https://github.com/alvinlindstam/grapheme>`__.\n\nGiven a list of tokens, we can leverage the native `unicodedata <https://docs.python.org/3/library/unicodedata.html>`__ to:\n\n* see if a token is a unicode Symbol (an emoji)\n* get the codepoint for the emoji, and\n* get the name of the emoji.\n\nIf a token is a grapheme and not a character, there won't be a record of what it is in unicodedata. In that case emojificate defaults to a human-readable version of the shortcode provided by `emoji <https://github.com/carpedm20/emoji>`__. \n\nFrom there, we construct an ``<img>`` replacement for the emoji:\n\n* Use images from `twemoji <https://github.com/twitter/twemoji>`__, Twitter's emoji set (if the URL exists)\n* Have an ``alt`` parameter containing the original emoji. This allows for copying-pasting.\n* Use the name of the emoji in the ``title`` parameter. This allows for hover-tooltips.\n* Add an ``aria-label`` for screen-reader accessibility.\n\nFor more information, see `Solve For Emoji <https://glasnt.com/blog/solve-for-emoji/>`__.\n\nImplementation in other languages\n---------------------------------\n\nRuby\n~~~~~\n\n.. code-block:: ruby\n\n require 'gemoji'\n\n def cdn\n \"https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/72x72/\"\n end\n\n def emojificate(string)\n string.split(\"\").each do |s|\n e = Emoji.find_by_unicode(s)\n if e then\n u = s.ord.to_s(16) # e.g. 1f431\n d = e.description # e.g. \"cat face\"\n img = \"<img src=\\\"#{cdn}/#{u}.png\\\" alt=\\\"#{s}\\\" title=\\\"#{d}\\\" aria-label=\\\"Emoji: #{d}\\\">\"\n print img\n else\n print s\n end\n end\n end\n",
"bugtrack_url": null,
"license": "New BSD",
"summary": "Convert emoji in HTML to fallback images, alt text, title text, and aria labels.",
"version": "0.7.0",
"split_keywords": [
"emoji",
"accessibility",
"a11y"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c8e1170a6e4f7118034409ba4adcbe2a44b7230c3d7943dddd89250e09938d2a",
"md5": "0bb7595d09a5031cca220022765e73f4",
"sha256": "fad26c7dfb0975d8c31d1e61bfb5a7f47320088d5ba295154548bc2c1978b5d4"
},
"downloads": -1,
"filename": "emojificate-0.7.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "0bb7595d09a5031cca220022765e73f4",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 7496,
"upload_time": "2023-01-12T23:03:58",
"upload_time_iso_8601": "2023-01-12T23:03:58.775230Z",
"url": "https://files.pythonhosted.org/packages/c8/e1/170a6e4f7118034409ba4adcbe2a44b7230c3d7943dddd89250e09938d2a/emojificate-0.7.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a641e3ec5e859ace64102c3c3b8d868df7858b5a182c8aa389bc642842c5dd3f",
"md5": "3d759f2e27a8a14fdfeed6f58636c033",
"sha256": "78836f3592d6dd8d02cdbdecefe2375fe462f871631c1c756bfacb508c25e579"
},
"downloads": -1,
"filename": "emojificate-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "3d759f2e27a8a14fdfeed6f58636c033",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 26286,
"upload_time": "2023-01-12T23:04:00",
"upload_time_iso_8601": "2023-01-12T23:04:00.256038Z",
"url": "https://files.pythonhosted.org/packages/a6/41/e3ec5e859ace64102c3c3b8d868df7858b5a182c8aa389bc642842c5dd3f/emojificate-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-12 23:04:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "glasnt",
"github_project": "emojificate",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "emojificate"
}