Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render unicode emoji with image fallback #779

Closed
jhildenbiddle opened this issue Feb 21, 2019 · 9 comments
Closed

Render unicode emoji with image fallback #779

jhildenbiddle opened this issue Feb 21, 2019 · 9 comments

Comments

@jhildenbiddle
Copy link
Member

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

@timaschew
Copy link
Member

What is your idea to support GitHub based aliases? I don't see any unique short names on this page: https://unicode.org/emoji/charts/full-emoji-list.html
On another I saw some other project which use the same source, but there are ambiguous keywords which are assigned to multiple emojis sometimes.

@jhildenbiddle
Copy link
Member Author

jhildenbiddle commented 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.com/githubassets/images/icons/emoji/unicode/1f44d.png?v8",
  ...
  "thumbsup": "https://github.com/githubassets/images/icons/emoji/unicode/1f44d.png?v8",
  ...
}

// Alias  : "+1" or "thumbsup"
// Unicode: "1f44d"
// URL    : "https://github.com/githubassets/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.com/githubassets/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.com/githubassets/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?

@jhildenbiddle
Copy link
Member Author

BTW, there are quite a few GitHub emoji lists generated from the GitHub API that we can direct users to:

We should either reference once of these or provide our own auto-generated table in the official documentation.

@timaschew
Copy link
Member

Sounds very good! Thanks for providing all the details.

I see now that the unicode is available in the URL 🙈

One suggestion: Some emojis have multiple unicode units/blocks? for example flags:

{
  "norway": {
    "unicode": ["1f1f3", "1f1f4"],
    "url": "https://github.com/githubassets/images/icons/emoji/unicode/1f1f3-1f1f4.png?v8"
  }
}

I've just realized, that the emojis on unicode.org have sometimes more than two units, but on GitHub they have maximal two units always. For instance the hash has three units on unicode.org
and on GitHub only two: https://github.com/githubassets/images/icons/emoji/unicode/0023-20e3.png?v8

But both variants are working.

@timaschew
Copy link
Member

Which milestone for this issues? 4.x or 5.x

@jhildenbiddle
Copy link
Member Author

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.

@trusktr
Copy link
Member

trusktr commented Jun 21, 2020

@sy-records handled this in #1188

If we want to improve on it (f.e. make a bot to keep it updated, etc) let's open new issues for each update.

@trusktr trusktr closed this as completed Jun 21, 2020
@jhildenbiddle jhildenbiddle removed this from the 5.x milestone Jun 21, 2020
@jhildenbiddle
Copy link
Member Author

jhildenbiddle commented Feb 3, 2022

Reopening since #1188 does not address the issue/enhancements mentioned.

There are multiple goals here:

  1. Render native emoji where supported (which is basically everywhere in 2022).
  2. Render all emoji without requiring site owners to use Docsify's emoji plugin.
  3. Generate emoji data from GitHub API instead of manually updating (see chore: sync emojis #1745 as an example).

More details above (#779 (comment)). Automating the update process via a bot isn't necessary. A build task and appropriate automated tests would be sufficient, but these are implementation details and not the end goal.

Here is a screenshot showing two different emoji rendered using native emoji (macOS in the screenshot since that's what I'm running) and on a Docsify site both with and without the emoji.js plugin:

CleanShot 2022-02-03 at 18 11 28@2x

Things to note:

  • Native emoji are more performant as they do not require a network request for a remote image
  • Native emoji allow users to copy/paste individually or as blocks of text.
  • Native emoji are more familiar to users as they are native to the platform they are using
  • Docsify is able to render some emoji without the emoji.js plugin (:smile:) but not others (:1st_place_medal:). This is unnecessarily confusing for users. We can simplify this by either:
    • Deprecating the emoji.js plugin and allowing Docsify to render all emoji by default. Users that do not wish to render emoji can use the noEmoji option. This would be my preference given the popularity of emoji.
    • Removing the ability to render emoji from Docsify core and require the emoji.js plugin to render emoji. This would make the purpose of the emoji plugin clear and reduce the size of the core Docsify bundle. This would not be my preference, but I can see how kilobyte-sensitive people may prefer it.

@docsifyjs/core -- Thoughts?

@jhildenbiddle
Copy link
Member Author

See #1746, which is currently a draft/POC PR that addresses items 1 and 2 in the above comment.

Koooooo-7 added a commit that referenced this issue Oct 26, 2022
* fix: packages/docsify-server-renderer/package.json & packages/docsify-server-renderer/package-lock.json to reduce vulnerabilities (#1715)

The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-DOCSIFY-1090577

* fix: correctly fix missing +1, -1 (#1722)

* Update LICENSE

* mention that SSR is experimental and incomplete, prevent people from using it thinking it is ready for prime time

* refactor: Update test environments and lint configuration (#1736)

* Update test environments and lint configuration

Update Jest (unit + integration) and Playwright (e2e) test environments. Includes stability improvements for e2e tests using newer, more stable methods per the Playwright docs.

- Update Jest 26 => 27
- Update Jest-related libs (babel parser)
- Update Playwright 1.8 => Playwright Test 1.18
- Update GitHub CI (action versions, job parallelization, and matrices)
- Update ESLint 5 => 8
- Update ESLint-related libs (parser, prettier, Jest, Playwright)
- Fix test failures on M1-based Macs
- Fix e2e stability issues by replacing PW $ method calls
- Fix ESLint errors
- Fix incorrect CI flag on Jest runs (-ci => --ci)
- Refactor e2e test runner from Jest to Playwright Test
- Refactor e2e test files for Playwright Test
- Refactor fix-lint script name to lint:fix for consistency
- Refactor npm scripts order for readability
- Remove unnecessary configs and libs
- Remove example image snapshots

* chore: bump node-fetch in /packages/docsify-server-renderer (#1738)

Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.6 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Commits](node-fetch/node-fetch@v2.6.6...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* docs: update readme (#1740)

* fix: Coverpage when content > viewport height (#1744)

* fix: .gitignore paths
* fix: Coverpage when content > viewport height

fix #381

* chore: sync emojis (#1745)

* fix: Legacy bugs (styles, site plugin error, and dev server error) (#1743)

* Add try/catch w/ error message to plugin calls

* Update lifecycle.js

* Update lifecycle.js

* Fix docsify-plugin-carbon error

* Fix ESLint errors

* Simplify conditional JS loading

* Fix styles in legacy browser w/o CSS var support

* Fix gitignore paths

* Fix BrowserSync IE error

* Fix search field presentation in IE11

- Removed fixed height and allow element to size naturally via font-size and padding
- Remove default "x" rendered on IE input fields

* Revert "Update lifecycle.js"

This reverts commit 2a58be6.

* Revert "Update lifecycle.js"

This reverts commit 67c5410.

* Revert "Add try/catch w/ error message to plugin calls"

This reverts commit 631e924.

* Fix docsify-plugin-carbon error & ESLint errors

Co-authored-by: 沈唁 <52o@qq52o.cn>

* fix: package.json & package-lock.json to reduce vulnerabilities (#1756)

The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/SNYK-JS-PRISMJS-2404333

* chore: bump follow-redirects from 1.14.7 to 1.14.9 (#1757)

Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.9.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.14.7...v1.14.9)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: bump prismjs in /packages/docsify-server-renderer (#1760)

Bumps [prismjs](https://github.com/PrismJS/prism) from 1.26.0 to 1.27.0.
- [Release notes](https://github.com/PrismJS/prism/releases)
- [Changelog](https://github.com/PrismJS/prism/blob/master/CHANGELOG.md)
- [Commits](PrismJS/prism@v1.26.0...v1.27.0)

---
updated-dependencies:
- dependency-name: prismjs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: Native emoji w/ image-based fallbacks and improved parsing (#1746)

* Render native emoji with image fallback

Fix #779

* Deprecate emoji plugin

* Add emoji tests

* Remove console.log statement

* Fix emoji image alt attribute

* Set nativeEmoji to false by default (non-breaking)

* Fix parsing emoji in HTML comments and script tags

* Add nativeEmoji and update noEmoji details

* Add Emoji plugin deprecation notice

* Fix ESLint issues

* Create build:emoji task

- Auto-generate emoji data from GitHub API
- Auto-generate emoji markdown for website
- Add emoji page to navigation

* Fix rendering of GitHub emoji without unicode

* Adjust and match size of native and image emoji

* Update emoji test snapshot

* Update docs test snapshot

* Fix ci/codesandbox error

* Update native emoji font-stack

* Fix rendering of native multi-character emoji

* Kick GitHub Workflow

* Replace rollup’s uglify plugin with terser

* Switch “npm ci” instead of “npm i” for stability

* Change emoji data from default to named export

* Revert "Replace rollup’s uglify plugin with terser"

This reverts commit 7ba8513.

* Revert "Switch “npm ci” instead of “npm i” for stability"

This reverts commit d52b476.

* Revert "Change emoji data from default to named export"

This reverts commit 3f2dd46.

* Specify codesandbox template and node version

* Update codesandbox config

* Revert "Revert "Replace rollup’s uglify plugin with terser""

This reverts commit e06fed4.

* Revert "Revert "Revert "Replace rollup’s uglify plugin with terser"""

This reverts commit 27d4952.

* Update codesandbox config

* Revert "Update codesandbox config"

This reverts commit 5120dd2.

* Fix codesandbox uglify error

* Emoji docs tweaks

* Restore and update emoji plugin code

* Restore and update emoji plugin docs

* Prettier updates

* Match lowercase shortcodes only

Co-authored-by: Koy Zhuang <369491420@qq.com>

* feat: Emoji build (#1766)

* Fix incorrect file name

* Improve build

- Display emoji API URL
- Display number of emoji entries retrieved from API
- Distinguish between creating and updating files
- Catch and display errors (gracefully fail for offline work)
- Add “DO NOT EDIT” comment to generated output

* Add emoji to automated build

* Remove emoji plugin from dev index.html

* chore: Remove dompurify (#1490)

* chore: update develop branch preview link (#1772)

* feat: Plugin error handling (#1742)

* Fix: ready/doneEach order with async afterEach (#1770)

* docs: Update configuration options (#1773)

* docs: Minor fixes to plugin docs (#1774)

* chore: update vercel link (#1775)

* chore: update vercel link

* chore: update vercel logo (#1776)

* chore: update vercel logo

* chore: update vercel logo

* chore: remove vercel link form github pages

* chore: update style

* chore: update readme

* chore: update readme

* chore: update readme

* chore: Update CONTRIBUTING.md (#1782)

Update URL of "How to Contribute to an Open Source Project on GitHub" link. The old one send the user to a 404 page where egghead suggest the new and correct URL. So, this change send the user direct to the correct URL.

* chore: bump minimist from 1.2.5 to 1.2.6 (#1787)

Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Virtual Routes Support (#1799)

* add first test

* new VirtualRoutes mixin that handles routes. fetch tries to use VirtualRoutes. default config updated

* cover all basic use cases

* regex matching in routes

* covered all virtual routes tests

* added hack to fix config test on firefox

* removed formatting regex matches into string routes

* added support for "next" function

* added docs

* navigate now supports both hash and history routerModes

* waiting for networkidle in navigateToRoute helper

* promiseless implementation

* remove firefox workaround from catchPluginErrors test, since we no longer use promises

* updated docs

* updated docs for "alias" as well

* minor rephrasing

* removed non-legacy code from exact-match; updated navigateToRoute helper to infer router mode from page

* moved endsWith from router utils to general utils; added startsWith util; refactored makeExactMatcher to use both

* updated docs per feedback

* moved navigateToRoute helper into the virtual-routes test file

* moved navigateToRoute to top of file

* updated docs per pr comments

* docs: update the name for "Simplified Chinese" (#1811)

* update the name for "Simplified Chinese"

* update the name for "Simplified Chinese"

* update the name for "Simplified Chinese"

* fix: cornerExternalLinkTarget config. (#1814)

* Improve README.md sentence (#1817)

* chore: bump jpeg-js from 0.4.3 to 0.4.4 (#1820)

Bumps [jpeg-js](https://github.com/eugeneware/jpeg-js) from 0.4.3 to 0.4.4.
- [Release notes](https://github.com/eugeneware/jpeg-js/releases)
- [Commits](jpeg-js/jpeg-js@v0.4.3...v0.4.4)

---
updated-dependencies:
- dependency-name: jpeg-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: bump parse-url from 6.0.0 to 6.0.2 (#1833)

Bumps [parse-url](https://github.com/IonicaBizau/parse-url) from 6.0.0 to 6.0.2.
- [Release notes](https://github.com/IonicaBizau/parse-url/releases)
- [Commits](https://github.com/IonicaBizau/parse-url/commits)

---
updated-dependencies:
- dependency-name: parse-url
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Docs: Fix plugin insertion order in docs (#1850)

* fix: Ignore emoji shorthand codes in URIs (#1847)

* fix: Ignore emoji shorthand codes in URIs

Fixes: #1823

* test: Add test for emoji in anchor body

* fix: Handle support for URIs used in additional contexts

Examples:

- Without explicit scheme (i.e. starting with `//`)
- In single and double quote strings
- Within unquoted HTML tag attributes
- In css `url()` values

Co-authored-by: John Hildenbiddle <jhildenbiddle@users.noreply.github.com>

* fix: fix docsify-ignore in seach title. (#1872)

* fix: fix search with no content. (#1878)

* docs: Update GitHub default branch from to 'main' (#1883)

* chore: upgrade caniuse-lit. (#1879)

* chore: bump trim-newlines and lerna (#1895)

Bumps [trim-newlines](https://github.com/sindresorhus/trim-newlines) and [lerna](https://github.com/lerna/lerna/tree/HEAD/core/lerna). These dependencies needed to be updated together.

Updates `trim-newlines` from 1.0.0 to 3.0.1
- [Release notes](https://github.com/sindresorhus/trim-newlines/releases)
- [Commits](https://github.com/sindresorhus/trim-newlines/commits)

Updates `lerna` from 3.22.1 to 5.5.1
- [Release notes](https://github.com/lerna/lerna/releases)
- [Changelog](https://github.com/lerna/lerna/blob/main/core/lerna/CHANGELOG.md)
- [Commits](https://github.com/lerna/lerna/commits/v5.5.1/core/lerna)

---
updated-dependencies:
- dependency-name: trim-newlines
  dependency-type: indirect
- dependency-name: lerna
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: filter null node first. (#1909)

* [build]: 4.12.3

* [build] 4.12.4

* chore: add changelog 4.12.4

* update: update dependencies.

* fix: fix test.

* fix: upgrade dependencies.

* [build] 4.13.0

* chore: add changelog 4.13.0

* chore: add changelog v4.13.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Snyk bot <snyk-bot@snyk.io>
Co-authored-by: ChoKaPeek <ChoKaPeek@users.noreply.github.com>
Co-authored-by: Joe Pea <joe@trusktr.io>
Co-authored-by: John Hildenbiddle <jhildenbiddle@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: 沈唁 <52o@qq52o.cn>
Co-authored-by: Bernal I. Hernández <102492790+bernalherndz@users.noreply.github.com>
Co-authored-by: Roy Sommer <illBeRoy@users.noreply.github.com>
Co-authored-by: Xavi Lee <awxiaoxian2020@163.com>
Co-authored-by: Shaun Bharat <79479981+shaunbharat@users.noreply.github.com>
Co-authored-by: Soc Sieng <socsieng@users.noreply.github.com>
Co-authored-by: Mike Mwanje <mwanjemike767@gmail.com>
Koooooo-7 added a commit that referenced this issue Oct 26, 2022
* Render native emoji with image fallback

Fix #779

* Deprecate emoji plugin

* Add emoji tests

* Remove console.log statement

* Fix emoji image alt attribute

* Set nativeEmoji to false by default (non-breaking)

* Fix parsing emoji in HTML comments and script tags

* Add nativeEmoji and update noEmoji details

* Add Emoji plugin deprecation notice

* Fix ESLint issues

* Create build:emoji task

- Auto-generate emoji data from GitHub API
- Auto-generate emoji markdown for website
- Add emoji page to navigation

* Fix rendering of GitHub emoji without unicode

* Adjust and match size of native and image emoji

* Update emoji test snapshot

* Update docs test snapshot

* Fix ci/codesandbox error

* Update native emoji font-stack

* Fix rendering of native multi-character emoji

* Kick GitHub Workflow

* Replace rollup’s uglify plugin with terser

* Switch “npm ci” instead of “npm i” for stability

* Change emoji data from default to named export

* Revert "Replace rollup’s uglify plugin with terser"

This reverts commit 7ba8513.

* Revert "Switch “npm ci” instead of “npm i” for stability"

This reverts commit d52b476.

* Revert "Change emoji data from default to named export"

This reverts commit 3f2dd46.

* Specify codesandbox template and node version

* Update codesandbox config

* Revert "Revert "Replace rollup’s uglify plugin with terser""

This reverts commit e06fed4.

* Revert "Revert "Revert "Replace rollup’s uglify plugin with terser"""

This reverts commit 27d4952.

* Update codesandbox config

* Revert "Update codesandbox config"

This reverts commit 5120dd2.

* Fix codesandbox uglify error

* Emoji docs tweaks

* Restore and update emoji plugin code

* Restore and update emoji plugin docs

* Prettier updates

* Match lowercase shortcodes only

Co-authored-by: Koy Zhuang <369491420@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants