From: Pascal Date: Thu, 16 Oct 2025 14:28:41 +0000 (+0200) Subject: fix: added a normalization step for MathJax-style \[\] and \(\) delimiters (#16599) X-Git-Tag: upstream/0.0.7011~230 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=683fa6ba4ed3a23b939d3e11e6dc860bd47a0ccf;p=pkg%2Fggml%2Fsources%2Fllama.cpp fix: added a normalization step for MathJax-style \[\] and \(\) delimiters (#16599) * fix: added a normalization step for MathJax-style \[\] and \(\) delimiters So inline and block equations are converted before KaTeX rendering, enabling proper display of model-generated LaTeX in the WebUI * chore: update webui build output --- diff --git a/tools/server/public/index.html.gz b/tools/server/public/index.html.gz index 1c62ebe9..34818012 100644 Binary files a/tools/server/public/index.html.gz and b/tools/server/public/index.html.gz differ diff --git a/tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte b/tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte index 24d29c2b..1f4caa90 100644 --- a/tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte +++ b/tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte @@ -154,9 +154,20 @@ return mutated ? tempDiv.innerHTML : html; } + function normalizeMathDelimiters(text: string): string { + return text + .replace(/(^|[^\\])\\\[((?:\\.|[\s\S])*?)\\\]/g, (_, prefix: string, content: string) => { + return `${prefix}$$${content}$$`; + }) + .replace(/(^|[^\\])\\\(((?:\\.|[\s\S])*?)\\\)/g, (_, prefix: string, content: string) => { + return `${prefix}$${content}$`; + }); + } + async function processMarkdown(text: string): Promise { try { - const result = await processor().process(text); + const normalized = normalizeMathDelimiters(text); + const result = await processor().process(normalized); const html = String(result); const enhancedLinks = enhanceLinks(html);