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

Fix emoji parser for +1 emoji #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kramdown/parser/gfm/emoji_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GFM

EMOJI_NAMES = Emoji.all.flat_map(&:aliases).freeze
REGISTRY = EMOJI_NAMES.zip(EMOJI_NAMES).to_h.freeze
EMOJI_PATTERN = /:(\w+):/
EMOJI_PATTERN = /:([\w\+]+):/
Copy link

@allisonphillips allisonphillips Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not covering 👎🏾 / - is not part of the character class matched by \w, and you shouldn't need to escape + if it's inside of a character class ([ ] \ - ^ are the characters that would need escaping):

Suggested change
EMOJI_PATTERN = /:([\w\+]+):/
EMOJI_PATTERN = /:([\w\-+]+):/

That said, there are a lot of places that don't support +1/-1, they are effectively aliases that were added to gemoji that map to the actual unicode CLDR short names (thumbs up and thumbs down)


# Based on the path rendered by `jemoji` plugin on GitHub Pages.
DEFAULT_ASSET_PATH = 'https://github.githubassets.com/images/icons/emoji'
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/codeblock_fenced.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

<p>indent with 2 spaces</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">hello</span><span class="dl">"</span><span class="p">);</span>
<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nx">console</span><span class="p">.</span><span class="nf">log</span><span class="p">(</span><span class="dl">"</span><span class="s2">hello</span><span class="dl">"</span><span class="p">);</span>
</code></pre></div></div>
4 changes: 4 additions & 0 deletions test/testcases/emoji.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<p>Lorem ipsum dolor <img class="emoji" title=":smile:" alt=":smile:" src="https://github.githubassets.com/images/icons/emoji/unicode/1f604.png" height="20" width="20" /> sit amet</p>

<p>Lorem ipsum dolor <img class="emoji" title=":+1:" alt=":+1:" src="https://github.githubassets.com/images/icons/emoji/unicode/1f44d.png" height="20" width="20" /> sit amet</p>

<p>Lorem ipsum dolor <img class="emoji" title=":100:" alt=":100:" src="https://github.githubassets.com/images/icons/emoji/unicode/1f4af.png" height="20" width="20" /> sit amet</p>

<p>Lorem ipsum dolor :custom: sit amet</p>

<p>Lorem ipsum dolor <code>:smile:</code> sit amet</p>
Expand Down
4 changes: 4 additions & 0 deletions test/testcases/emoji.text
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Lorem ipsum dolor :smile: sit amet

Lorem ipsum dolor :+1: sit amet

Lorem ipsum dolor :100: sit amet

Lorem ipsum dolor :custom: sit amet

Lorem ipsum dolor `:smile:` sit amet
Expand Down