Skip to content

Commit

Permalink
rehype-katex: fix crash on katex error
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 19, 2024
1 parent 6dbaf1e commit 3efc101
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/rehype-katex/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <https://github.com/remarkjs/react-markdown/issues/853>
try {
result = katex.renderToString(value, {
...settings,
displayMode,
strict: 'ignore',
throwOnError: false
})
}
// Generate similar markup if this is an other error.
// See: <https://github.com/KaTeX/KaTeX/blob/5dc7af0/docs/error.md>.
else {
} catch {
// Generate similar markup if this is an other error.
// See: <https://github.com/KaTeX/KaTeX/blob/5dc7af0/docs/error.md>.
result = [
{
type: 'element',
Expand Down

0 comments on commit 3efc101

Please sign in to comment.