question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render unicode emoji with image fallback

See original GitHub issue

(Moving discussion of rendering unicode emoji from #768 to a separate thread)

From #768:

According to caniemoji.com, unicode emoji are supported all the way back to Windows 7, macOS 10.7, Android 4.4, and iOS 5. Switching to unicode emoji would remove emoji <img> requests and render emoji native to each platform. Seems like a better route to go, so long as the unsupported OS+Browser combinations aren’t a concern. This article will likely be helpful if/when the switch to unicode happens.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
jhildenbiddlecommented, Feb 24, 2019

My initial thought was to just leverage the GitHub emoji API to get both the alias and the unicode value:

// API
{
  "+1": "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8",
  ...
  "thumbsup": "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8",
  ...
}

// Alias  : "+1" or "thumbsup"
// Unicode: "1f44d"
// URL    : "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8"

GitHub has already done the work of mapping aliases to unicode values and images (the file name is the unicode value), as well as adding logical duplicates like the example above.

As for the implementation:

  • Emoji data should be embedded in docsify.js, not requested from the GitHub API by the client.

  • GitHub data should be transformed to better fit docsify’s usage and reduce client-side parsing. For example, instead of embedding GitHub’s API data as-is:

    {
      "+1": "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8",
      ...
    }
    
    // const emojiURL  = emoji["+1"];
    // const emojiCode = emojiURL.slice(emojiURL.lastIndexOf('/') + 1, emojiURL.lastIndexOf('.'));
    
    

    The data should be transformed to allow fast unicode and URL lookups:

    {
      "+1": {
        unicode: "1f44d",
        url: "https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png?v8"
      }
      ...
    }
    
    // const emojiURL  = emoji["+1"].url
    // const emojiCode = emoji["+1"].unicode
    
  • An automated task should be added that refreshes docsify’s local copy of GitHub API data, transforms the data as described above, and stores the result in a file that docsify can import/require at build time.

  • A test for emoji support will determine if a unicode character or image is rendered. I’d likely reference Modernizr’s emoji test and build from that. The test only needs to done one time, so the performance impact should be negligible.

  • Some minor CSS tweaks may be required for unicode emoji characters, and it will most likely make sense to wrap them in a <span> tag with a unique class.

These non-breaking changes will provide the following benefits:

  1. Improved emoji rendering performance by removing image requests on platforms that support unicode emoji
  2. Rendering of native emoji on platforms that support unicode emoji
  3. Additional emoji alias support (docsify currently support 886, GitHub support 1508)
  4. Simplified emoji support for docsify devs (via automated task described above)

How does that sound?

1reaction
jhildenbiddlecommented, Apr 23, 2019

Depends on how important you think this is. My preference would be to focus on getting the repo up-to-date (PRs, IE compatibility, triaging issues, etc.) for the next release (4.x) and push enhancements (like this) off to the following release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent Unicode characters from rendering as emoji in ...
Directly use a manually-maintained regex which matches the blocks where the newest version of Unicode puts its emoji and their modifiers.
Read more >
Our journey in switching to native Unicode emoji - GitLab
The switch from image-based emoji to native Unicode wasn't a straightforward journey and included many intricacies to get production ready.
Read more >
The struggle of using native emoji on the web
Emoji are a standard overseen by the Unicode Consortium. ... Your browser can render Emoji 13.1, released in September 2020.
Read more >
UTS #51: Unicode Emoji
This document defines the structure of Unicode emoji characters and sequences, and provides data to support that structure, such as which characters are ......
Read more >
Using Emojis in HTML, CSS, and JavaScript - KIRUPA
How you specify the codepoint is a bit different than what we saw for HTML. All you have to do is remove the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found