From 8ee25f625ac98c132c34b89fe1f8961db869155c Mon Sep 17 00:00:00 2001 From: 8Nothing8 Date: Tue, 30 Jun 2026 22:27:32 +0800 Subject: [PATCH] fix(ui): fallback math rendering for multiline $$ blocks marked-katex-extension v5.1.6 fails to match display math ($$...$$) that spans multiple lines because its inline tokenizer regex likely does not use the dotAll (/s) flag, so a newline between \begin{aligned} and \end{aligned} causes the block to be treated as plain text. The fix: wrap the non-nativeParser path to post-process the HTML output with the existing renderMathExpressions() function, which already uses a multiline-aware regex (/\$\$([\s\S]*?)\$\$/g) to catch any $$ blocks the extension missed. Successfully-rendered blocks contain no residual $$ and are safe from double-processing; code/pre/kbd blocks are protected by the existing skip pattern in renderMathExpressions(). --- packages/ui/src/context/marked.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/context/marked.tsx b/packages/ui/src/context/marked.tsx index e93c74a0cb05..546e0dd7189f 100644 --- a/packages/ui/src/context/marked.tsx +++ b/packages/ui/src/context/marked.tsx @@ -517,6 +517,11 @@ export const { use: useMarked, provider: MarkedProvider } = createSimpleContext( } } - return jsParser + return { + async parse(markdown: string): Promise { + const html = await Promise.resolve(jsParser.parse(markdown)) + return renderMathExpressions(html) + }, + } }, })