Skip to content

Commit 917cfab

Browse files
authored
Merge pull request microsoft#258365 from mjbvz/wittering-gazelle
Return original markup if katex fails
2 parents 5b78679 + 79d04c5 commit 917cfab

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
@@ -166,12 +166,20 @@ export namespace MarkedKatexExtension {
166166
};
167167
}
168168

169-
function createRenderer(katex: typeof import('katex').default, options: MarkedKatexOptions, newlineAfter: boolean): marked.RendererExtensionFunction {
169+
function createRenderer(katex: typeof import('katex').default, options: MarkedKatexOptions, isBlock: boolean): marked.RendererExtensionFunction {
170170
return (token: marked.Tokens.Generic) => {
171-
return katex.renderToString(token.text, {
172-
...options,
173-
displayMode: token.displayMode,
174-
}) + (newlineAfter ? '\n' : '');
171+
let out: string;
172+
try {
173+
out = katex.renderToString(token.text, {
174+
...options,
175+
throwOnError: true,
176+
displayMode: token.displayMode,
177+
});
178+
} catch {
179+
// On failure, just use the original text including the wrapping $ or $$
180+
out = token.raw;
181+
}
182+
return out + (isBlock ? '\n' : '');
175183
};
176184
}
177185

0 commit comments

Comments
 (0)