From 97fcccd91426093e909b9d8d3de68a591e179991 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Wed, 26 Feb 2025 16:47:14 -0500 Subject: [PATCH 1/2] fix(markdown): fix plain code fences not being transformed --- .../ConsoleInternal/components/markdown-view.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/module/src/ConsoleInternal/components/markdown-view.tsx b/packages/module/src/ConsoleInternal/components/markdown-view.tsx index 3db12086..f7fbe28f 100644 --- a/packages/module/src/ConsoleInternal/components/markdown-view.tsx +++ b/packages/module/src/ConsoleInternal/components/markdown-view.tsx @@ -51,8 +51,20 @@ export const markdownConvert = async (markdown: string, extensions?: ShowdownExt } }); - // Replace code fences with non markdown formatting relates tokens so that marked doesn't try to parse them as code spans - const markdownWithSubstitutedCodeFences = markdown.replace(/```/g, '@@@'); + const reverseString = (str: string) => str.split('').reverse().join(''); + + // replace code fences that end in a double curly brace (which are used by our custom md extensions) with non + // markdown formatting related tokens so that marked doesn't try to parse them as code spans + // + // we want to reverse the string before we do the substitution so that we only match the opening code fence which + // corresponds to the closing code fence with the double curly brace + const reversedMarkdown = reverseString(markdown); + const reverseMarkdownWithSubstitutedCodeFences = reversedMarkdown.replace( + /{{```((.|\n)*?)```/g, + '{{@@@$1@@@', + ); + const markdownWithSubstitutedCodeFences = reverseString(reverseMarkdownWithSubstitutedCodeFences); + const parsedMarkdown = await marked.parse(markdownWithSubstitutedCodeFences); // Swap the temporary tokens back to code fences before we run the extensions let md = parsedMarkdown.replace(/@@@/g, '```'); From d069c2d3bf0aa046362db6cb6a94078d007122fa Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Thu, 27 Feb 2025 13:45:07 -0500 Subject: [PATCH 2/2] lint --- .../module/src/ConsoleInternal/components/markdown-view.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/module/src/ConsoleInternal/components/markdown-view.tsx b/packages/module/src/ConsoleInternal/components/markdown-view.tsx index f7fbe28f..08a32a93 100644 --- a/packages/module/src/ConsoleInternal/components/markdown-view.tsx +++ b/packages/module/src/ConsoleInternal/components/markdown-view.tsx @@ -51,7 +51,11 @@ export const markdownConvert = async (markdown: string, extensions?: ShowdownExt } }); - const reverseString = (str: string) => str.split('').reverse().join(''); + const reverseString = (str: string) => + str + .split('') + .reverse() + .join(''); // replace code fences that end in a double curly brace (which are used by our custom md extensions) with non // markdown formatting related tokens so that marked doesn't try to parse them as code spans