Skip to content

markup: render emoji shortcodes in Markdown like GitHub - #8600

Merged
unknwon merged 2 commits into
mainfrom
markdown-emoji
Nov 16, 2026
Merged

unknwon merged 2 commits into
mainfrom
markdown-emoji

Conversation

@unknwon

@unknwon unknwon commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Describe the pull request

Markdown now renders emoji shortcodes like :tada: as emoji, the way GitHub does.

  • The names are GitHub's: the 1,913 Unicode emoji from gemoji, which match GitHub's /emojis list exactly. GitHub's 23 image-only names, e.g., :octocat: and :shipit:, stay as text because they need GitHub-hosted images.
  • Shortcodes are replaced where GitHub replaces them, checked against GitHub's Markdown API: in text, link text, headings, tables, alerts and <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.
  • GitHub decides per HTML text node: when the first :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. So 10:30:45 :tada: and foo:tada: stay as text, while :tada: a:b:c becomes 🎉 a🅱️c. Tags, mentions, issue references and commit links start new text nodes, and end tags without a start tag do not.
  • Heading anchors are unchanged, e.g., # :tada: Release keeps user-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

Issue and comment with emoji

At 375px
At 375px

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code and provided the test plan below.
  • I have added an entry to CHANGELOG.

Test plan

  1. go test ./internal/markup/... passes. TestMarkdown_Emoji runs 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.
  2. Differential test against GitHub's Markdown API: all 1,913 names render the same characters, and about 7,000 random documents mixing shortcodes, punctuation, whitespace, emphasis, links, code and raw HTML render the same text in gfm and markdown mode. The remaining differences are in which mentions, issue references and SHAs each side links, which predates this change.
  3. Ran a -tags prod build 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.

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.
unknwon added a commit that referenced this pull request Nov 16, 2026
@unknwon
unknwon merged commit 7488ded into main Nov 16, 2026
11 checks passed
@unknwon
unknwon deleted the markdown-emoji branch November 16, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant