Skip to content

Commit 79d04c5

Browse files
committed
Return original markup if katex fails
1 parent c018342 commit 79d04c5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/vs/workbench/contrib/markdown/browser/markedKatexSupport.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,20 @@ export namespace MarkedKatexExtension {
150150
};
151151
}
152152

153-
function createRenderer(katex: typeof import('katex').default, options: MarkedKatexOptions, newlineAfter: boolean): marked.RendererExtensionFunction {
153+
function createRenderer(katex: typeof import('katex').default, options: MarkedKatexOptions, isBlock: boolean): marked.RendererExtensionFunction {
154154
return (token: marked.Tokens.Generic) => {
155-
return katex.renderToString(token.text, {
156-
...options,
157-
displayMode: token.displayMode,
158-
}) + (newlineAfter ? '\n' : '');
155+
let out: string;
156+
try {
157+
out = katex.renderToString(token.text, {
158+
...options,
159+
throwOnError: true,
160+
displayMode: token.displayMode,
161+
});
162+
} catch {
163+
// On failure, just use the original text including the wrapping $ or $$
164+
out = token.raw;
165+
}
166+
return out + (isBlock ? '\n' : '');
159167
};
160168
}
161169

0 commit comments

Comments
 (0)