From ad42fb6eceffed7c4cc13f136352f9f1dd5a7096 Mon Sep 17 00:00:00 2001 From: ffedex Date: Fri, 3 Apr 2026 22:00:55 +0200 Subject: [PATCH] fix: skip emoji conversion inside code blocks --- shared/utils/emoji.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/shared/utils/emoji.ts b/shared/utils/emoji.ts index b617309226..a51b8ee372 100644 --- a/shared/utils/emoji.ts +++ b/shared/utils/emoji.ts @@ -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) as keyof typeof emojis + return emojis[key] || shortcode + } + return match + }, + ) }