Repository navigation
markup: render emoji shortcodes in Markdown like GitHub - #8600
Merged
Merged
Conversation
Shortcodes like 🎉 render as Unicode emoji with GitHub's names from gemoji, and in the same places GitHub replaces them: in text, links and headings, but not in code, and per text node only when its first shortcode follows a space or starts the node.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
Markdown now renders emoji shortcodes like
:tada:as emoji, the way GitHub does./emojislist exactly. GitHub's 23 image-only names, e.g.,:octocat:and:shipit:, stay as text because they need GitHub-hosted images.<kbd>, but not in code spans, code blocks or<pre>. Names are case sensitive. Inside<tt>, Gogs follows GitHub's comments, which replace them, rather than its file view, which does not, since Gogs renders both the same way.:name:-shaped run of a node follows a space, or only whitespace since the node started, every known shortcode in the node is replaced. Otherwise none is. So10:30:45 :tada:andfoo:tada:stay as text, while:tada: a:b:cbecomes🎉 a🅱️c. Tags, mentions, issue references and commit links start new text nodes, and end tags without a start tag do not.# :tada: Releasekeepsuser-content-tada-release, as on GitHub.The replacement runs in Dariomark's post-processing, in both the sanitizing fast path and the raw HTML path, so emails, the API and every page that renders Markdown show the same thing.
Performance. No measurable change on real documents (a README, a 12 KB doc page, the 45 KB CHANGELOG and 108 KB of docs) and no extra allocations per emoji. 64 KB of nothing but shortcodes renders 26% slower. The table adds no measurable startup time and grows the binary by about 94 KB.
Screenshots
Issue and comment
Checklist
Test plan
go test ./internal/markup/...passes.TestMarkdown_Emojiruns each case through the sanitizing path and the raw HTML path, and its expected output matches GitHub's API for the same input. Breaking any one rule (state across long text, line endings as boundaries, links splitting nodes, stray end tags, reusing the closing colon, link text) fails it.gfmandmarkdownmode. The remaining differences are in which mentions, issue references and SHAs each side links, which predates this change.-tags prodbuild and opened an issue with shortcodes in text, a list, a link, an alert and code, and a comment with a mention. Emoji render where expected, at 1280 and 375, with no sideways scroll at 375.