Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,18 @@ describe('extractLeadingEmoji', () => {
rest: 'Hello World 😀',
});
});

it('does not extract digits', () => {
expect(extractLeadingEmoji('11 Hello World')).toEqual({
emoji: null,
rest: '11 Hello World',
});
});

it('extract emoji digits', () => {
expect(extractLeadingEmoji('1️⃣ Hello World')).toEqual({
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added this extra test case, that was failing with your impl

emoji: '1️⃣',
rest: ' Hello World',
});
});
});
9 changes: 4 additions & 5 deletions packages/docusaurus-theme-common/src/utils/emojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ export function extractLeadingEmoji(input: string): {
return {emoji: null, rest: input};
}

// Leading grapheme contains an emoji (covers flags/ZWJ/skin tones)
if (
!/\p{Extended_Pictographic}/u.test(grapheme) &&
!/\p{Emoji}/u.test(grapheme)
) {
// Leading grapheme contains an emoji
// Covers flags/ZWJ/skin tones, excludes digits
// See https://github.com/facebook/docusaurus/pull/12072
if (!/^\p{RGI_Emoji}$/v.test(grapheme)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here's a better option, apparently, both our test cases now pass successfully

return {emoji: null, rest: input};
}

Expand Down
Loading