Skip to main content

emojificate

status 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.

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.

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.

From there, we construct an <img> replacement for the emoji:

  • Use images from 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.

Implementation in other languages

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

Metadata

Release files for emojificate 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for emojificate 0.7.0
File Size Uploaded Provenance Actions
emojificate-0.7.0.tar.gz 26.3 kB Without provenance Details for emojificate-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for emojificate 0.7.0
File Interpreter ABI Platform Actions
emojificate-0.7.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for emojificate-0.7.0-py2.py3-none-any.whl

Total release size: 33.8 kB

Release files / emojificate-0.7.0.tar.gz

Download URL emojificate-0.7.0.tar.gz
Size 26.3 kB
Tags Source
SHA-256 checksum
How to use checksums
78836f3592d6dd8d02cdbdecefe2375fe462f871631c1c756bfacb508c25e579
BLAKE2b-256 checksum
How to use checksums
a641e3ec5e859ace64102c3c3b8d868df7858b5a182c8aa389bc642842c5dd3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / emojificate-0.7.0-py2.py3-none-any.whl

Download URL emojificate-0.7.0-py2.py3-none-any.whl
Size 7.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fad26c7dfb0975d8c31d1e61bfb5a7f47320088d5ba295154548bc2c1978b5d4
BLAKE2b-256 checksum
How to use checksums
c8e1170a6e4f7118034409ba4adcbe2a44b7230c3d7943dddd89250e09938d2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for emojificate 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page