Skip to content

Commit 3efc101

Browse files
committed
rehype-katex: fix crash on katex error
Closes remarkjs/react-markdown#853.
1 parent 6dbaf1e commit 3efc101

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/rehype-katex/lib/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,19 @@ export default function rehypeKatex(options) {
101101
source: 'rehype-katex'
102102
})
103103

104-
// KaTeX can handle `ParseError` itself, but not others.
105-
if (ruleId === 'parseerror') {
104+
// KaTeX *should* handle `ParseError` itself, but not others.
105+
// it doesn’t always:
106+
// <https://github.com/remarkjs/react-markdown/issues/853>
107+
try {
106108
result = katex.renderToString(value, {
107109
...settings,
108110
displayMode,
109111
strict: 'ignore',
110112
throwOnError: false
111113
})
112-
}
113-
// Generate similar markup if this is an other error.
114-
// See: <https://github.com/KaTeX/KaTeX/blob/5dc7af0/docs/error.md>.
115-
else {
114+
} catch {
115+
// Generate similar markup if this is an other error.
116+
// See: <https://github.com/KaTeX/KaTeX/blob/5dc7af0/docs/error.md>.
116117
result = [
117118
{
118119
type: 'element',

0 commit comments

Comments
 (0)