fix: Catch MathML errors and render the "ERR" block instead.

This commit is contained in:
Daniel J. Geiger 2023-02-27 14:19:06 -06:00
parent 4c939cefad
commit 82b597ab8b

View File

@ -443,13 +443,25 @@ const math2Svg = (
: mathJax.amHtml.convert(text, userOptions),
)
: text;
let mmlError = false;
if (isMathJaxLoaded) {
const errDiv = document.createElement("div");
errDiv.innerHTML = mmlString;
mmlError =
errDiv.children[0].children.length > 0 &&
errDiv.children[0].children[0].nodeName === "merror";
}
// For rendering
const htmlString = isMathJaxLoaded
? mathJax.adaptor.outerHTML(mathJax.mmlSvg.convert(mmlString))
? mmlError
? errorSvg
: mathJax.adaptor.outerHTML(mathJax.mmlSvg.convert(mmlString))
: text;
// For accessibility
const ariaString = isMathJaxLoaded
? useSRE
? mmlError
? errorAria
: useSRE
? mathJax.mmlSre.toSpeech(mmlString)
: text
: mmlString;