From 3497b52ef832060a8cd5aae0f88a4e8b586678a2 Mon Sep 17 00:00:00 2001 From: Roman Date: Sat, 9 May 2026 01:51:17 +0100 Subject: [PATCH 1/3] fix: skip emoji conversion inside code blocks --- shared/utils/emoji.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/shared/utils/emoji.ts b/shared/utils/emoji.ts index b617309226..976ec555f0 100644 --- a/shared/utils/emoji.ts +++ b/shared/utils/emoji.ts @@ -1,5 +1,5 @@ // copied from https://github.com/markdown-it/markdown-it-emoji/blob/master/lib/data/full.mjs -const emojis = { +const emojis: Record = { '100': '💯', '1234': '🔢', 'grinning': '😀', @@ -1905,15 +1905,16 @@ const emojis = { 'wales': '🏴󠁧󠁢󠁷󠁬󠁳󠁿', } -const emojisKeysRegex = new RegExp( - Object.keys(emojis) - .map(key => `:${key}:`) - .join('|'), - 'g', -) -export function convertToEmoji(text: string): string { - return text.replace(emojisKeysRegex, match => { - const key = match.slice(1, -1) as keyof typeof emojis - return emojis[key] || match - }) +export function convertToEmoji(html: string): string { + return html.replace( + /(][\s\S]*?<\/code>|][\s\S]*?<\/pre>)|(:[\w+-]+:)/gi, + (match, codeBlock: string | undefined, shortcode: string | undefined) => { + if (codeBlock) return codeBlock + if (shortcode) { + const key = shortcode.slice(1, -1) + return emojis[key] ?? shortcode + } + return match + }, + ) } From 13cf4a1c3b723eaba99800f38c4e2c115e907fcd Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 9 May 2026 00:53:53 +0000 Subject: [PATCH 2/3] [autofix.ci] apply automated fixes --- shared/utils/emoji.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/utils/emoji.ts b/shared/utils/emoji.ts index 976ec555f0..1a647236f8 100644 --- a/shared/utils/emoji.ts +++ b/shared/utils/emoji.ts @@ -1905,14 +1905,14 @@ const emojis: Record = { 'wales': '🏴󠁧󠁢󠁷󠁬󠁳󠁿', } -export function convertToEmoji(html: string): string { +export function convertToEmoji(html: string): string { return html.replace( /(][\s\S]*?<\/code>|][\s\S]*?<\/pre>)|(:[\w+-]+:)/gi, (match, codeBlock: string | undefined, shortcode: string | undefined) => { if (codeBlock) return codeBlock if (shortcode) { const key = shortcode.slice(1, -1) - return emojis[key] ?? shortcode + return emojis[key] ?? shortcode } return match }, From ba04ebe12eda610a1dc5ceeabebd328f11b19877 Mon Sep 17 00:00:00 2001 From: Roman Date: Sun, 10 May 2026 01:44:43 +0100 Subject: [PATCH 3/3] test: add tests for `convertToEmoji` --- test/unit/shared/utils/emoji.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/unit/shared/utils/emoji.spec.ts diff --git a/test/unit/shared/utils/emoji.spec.ts b/test/unit/shared/utils/emoji.spec.ts new file mode 100644 index 0000000000..846860f1b9 --- /dev/null +++ b/test/unit/shared/utils/emoji.spec.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest' +import { convertToEmoji } from '#shared/utils/emoji' + +describe('convertToEmoji', () => { + it('converts :1234: to emoji', () => { + expect(convertToEmoji('

:1234:

')).toBe('

🔢

') + }) + + it('leaves :1234: in codeblocks untouched', () => { + expect(convertToEmoji(':1234:')).toBe(':1234:') + }) + + it('converts :1234: to emoji outside of codeblock', () => { + expect(convertToEmoji('

:1234:

:1234:')).toBe('

🔢

:1234:') + expect(convertToEmoji(':1234:

:1234:

')).toBe(':1234:

🔢

') + }) +})