Skip to content

Commit 683fa6b

Browse files
fix: added a normalization step for MathJax-style \[\] and \(\) delimiters (ggml-org#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
1 parent b22572e commit 683fa6b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tools/server/public/index.html.gz

113 Bytes
Binary file not shown.

tools/server/webui/src/lib/components/app/misc/MarkdownContent.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,20 @@
154154
return mutated ? tempDiv.innerHTML : html;
155155
}
156156
157+
function normalizeMathDelimiters(text: string): string {
158+
return text
159+
.replace(/(^|[^\\])\\\[((?:\\.|[\s\S])*?)\\\]/g, (_, prefix: string, content: string) => {
160+
return `${prefix}$$${content}$$`;
161+
})
162+
.replace(/(^|[^\\])\\\(((?:\\.|[\s\S])*?)\\\)/g, (_, prefix: string, content: string) => {
163+
return `${prefix}$${content}$`;
164+
});
165+
}
166+
157167
async function processMarkdown(text: string): Promise<string> {
158168
try {
159-
const result = await processor().process(text);
169+
const normalized = normalizeMathDelimiters(text);
170+
const result = await processor().process(normalized);
160171
const html = String(result);
161172
const enhancedLinks = enhanceLinks(html);
162173

0 commit comments

Comments
 (0)