From 0d8025e8ea916951a7651df8afdf0e4c425e342f Mon Sep 17 00:00:00 2001 From: Rachelle Hu Date: Mon, 7 Feb 2022 11:34:00 -0500 Subject: [PATCH 1/3] Emoji in code block, fix issue #329 --- functions/src/content.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/functions/src/content.ts b/functions/src/content.ts index 8f68446c4..050f66722 100644 --- a/functions/src/content.ts +++ b/functions/src/content.ts @@ -70,7 +70,13 @@ function replaceEmojis(md: string, emojis: Record): string { for (const k of Object.keys(emojis)) { const withColons = `:${k}:`; const asEmoji = emojis[k]; - content = content.replace(new RegExp(withColons, "g"), asEmoji); + const contentList = content.split("```"); + contentList.forEach((val, ind) => { + if (ind % 2 === 0) { + contentList[ind] = val.replace(new RegExp(withColons, "g"), asEmoji); + } + }); + content = contentList.join("```"); } return content; From 85a73dbc0c2e5eea1f48801d933741b4bacb29d7 Mon Sep 17 00:00:00 2001 From: Rachelle Hu Date: Tue, 8 Feb 2022 22:26:16 -0500 Subject: [PATCH 2/3] Update content.ts --- functions/src/content.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/functions/src/content.ts b/functions/src/content.ts index 050f66722..ca76da24b 100644 --- a/functions/src/content.ts +++ b/functions/src/content.ts @@ -66,20 +66,23 @@ export function renderContent( } function replaceEmojis(md: string, emojis: Record): string { - let content = md; + let content = md.split("\n"); + let isInCodeBlock = false; + for (const k of Object.keys(emojis)) { const withColons = `:${k}:`; const asEmoji = emojis[k]; - const contentList = content.split("```"); - contentList.forEach((val, ind) => { - if (ind % 2 === 0) { - contentList[ind] = val.replace(new RegExp(withColons, "g"), asEmoji); + content.forEach((val, ind) => { + if (val.includes("```")) { + isInCodeBlock = !isInCodeBlock; + } + if (!isInCodeBlock) { + content[ind] = val.replace(new RegExp(withColons, "g"), asEmoji); } }); - content = contentList.join("```"); } - return content; + return content.join("\n"); } /** From a6b288a0902978dbf0f84832e59ea65e87204d23 Mon Sep 17 00:00:00 2001 From: Rachelle Hu Date: Wed, 9 Feb 2022 10:06:30 -0500 Subject: [PATCH 3/3] Update functions/src/content.ts Co-authored-by: Sam Stern --- functions/src/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/src/content.ts b/functions/src/content.ts index ca76da24b..21aa86f8b 100644 --- a/functions/src/content.ts +++ b/functions/src/content.ts @@ -73,7 +73,7 @@ function replaceEmojis(md: string, emojis: Record): string { const withColons = `:${k}:`; const asEmoji = emojis[k]; content.forEach((val, ind) => { - if (val.includes("```")) { + if (val.trim().startsWith("```")) { isInCodeBlock = !isInCodeBlock; } if (!isInCodeBlock) {