From 3efc1018751e04a0d6de49acee605bce8fce04e2 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 19 Aug 2024 14:05:40 +0200 Subject: [PATCH] rehype-katex: fix crash on katex error Closes remarkjs/react-markdown#853. --- packages/rehype-katex/lib/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/rehype-katex/lib/index.js b/packages/rehype-katex/lib/index.js index 91c8054..1f858c8 100644 --- a/packages/rehype-katex/lib/index.js +++ b/packages/rehype-katex/lib/index.js @@ -101,18 +101,19 @@ export default function rehypeKatex(options) { source: 'rehype-katex' }) - // KaTeX can handle `ParseError` itself, but not others. - if (ruleId === 'parseerror') { + // KaTeX *should* handle `ParseError` itself, but not others. + // it doesn’t always: + // + try { result = katex.renderToString(value, { ...settings, displayMode, strict: 'ignore', throwOnError: false }) - } - // Generate similar markup if this is an other error. - // See: . - else { + } catch { + // Generate similar markup if this is an other error. + // See: . result = [ { type: 'element',