Make sure math equations are rendered sequentially (#294)

This commit is contained in:
Jonatan Kłosko 2021-05-25 14:36:55 +02:00 committed by GitHub
parent 122c6f27d7
commit 2e0195f658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,18 +79,18 @@ class Markdown {
// Replaces TeX formulas in string with rendered HTML using KaTeX.
__renderMathInString(string) {
const options = {
throwOnError: false,
errorColor: "inherit",
};
return string.replace(
/(\${1,2})([\s\S]*?)\1/g,
(match, delimiter, math) => {
const displayMode = delimiter === "$$";
return string
.replace(/\$\$([\s\S]*?)\$\$/g, (match, math) => {
return katex.renderToString(math, { ...options, displayMode: true });
})
.replace(/\$([\s\S]*?)\$/g, (match, math) => {
return katex.renderToString(math, options);
});
return katex.renderToString(math.trim(), {
displayMode,
throwOnError: false,
errorColor: "inherit",
});
}
);
}
}