Skip to content

Commit ca72b28

Browse files
committed
fix(markdown): gestion des erreurs Katex
1 parent a52bd94 commit ca72b28

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

app/js/markdown/latex.mjs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,26 @@ export function convertLatexExpressions(string, noBackticks) {
3232
.replaceAll("\\", "\\\\");
3333
// On convertit la formule mathématique en HTML avec Katex
3434
if (window.katex) {
35-
const stringWithLatex = window.katex.renderToString(
36-
mathInExpressionLatex,
37-
{
38-
displayMode: inlineMaths,
39-
},
40-
);
41-
string = string.replace(expressionLatex, stringWithLatex);
35+
try {
36+
const stringWithLatex = window.katex.renderToString(
37+
mathInExpressionLatex,
38+
{
39+
displayMode: inlineMaths,
40+
},
41+
);
42+
string = string.replace(expressionLatex, stringWithLatex);
43+
} catch (error) {
44+
if (error instanceof window.katex.ParseError) {
45+
const rendered =
46+
`Error in LaTeX '${mathInExpressionLatex}': ${error.message}`
47+
.replace(/&/g, "&")
48+
.replace(/</g, "<")
49+
.replace(/>/g, ">");
50+
string = string.replace(expressionLatex, rendered);
51+
} else {
52+
throw error;
53+
}
54+
}
4255
}
4356
}
4457
}

app/script.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)