mirror of
https://github.com/ankitects/anki.git
synced 2025-11-12 07:37:11 -05:00
Wrap Mathjax compilation into try/catch
This commit is contained in:
parent
f00f7f099f
commit
a1dde7c966
1 changed files with 12 additions and 6 deletions
|
|
@ -36,19 +36,25 @@ export function convertMathjax(
|
||||||
return getEmptyIcon(style);
|
return getEmptyIcon(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = globalThis.MathJax.tex2svg(input);
|
let output: Element;
|
||||||
const svg = output.children[0];
|
try {
|
||||||
|
output = globalThis.MathJax.tex2svg(input);
|
||||||
|
} catch (e) {
|
||||||
|
return ["Mathjax Error", String(e)];
|
||||||
|
}
|
||||||
|
|
||||||
if (svg.viewBox.baseVal.height === 16) {
|
const svg = output.children[0] as SVGElement;
|
||||||
|
|
||||||
|
if ((svg as any).viewBox.baseVal.height === 16) {
|
||||||
return getEmptyIcon(style);
|
return getEmptyIcon(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
let title = "";
|
let title = "";
|
||||||
|
|
||||||
if (svg.innerHTML.includes("data-mjx-error")) {
|
if (svg.innerHTML.includes("data-mjx-error")) {
|
||||||
svg.querySelector("rect").setAttribute("fill", "yellow");
|
svg.querySelector("rect")?.setAttribute("fill", "yellow");
|
||||||
svg.querySelector("text").setAttribute("color", "red");
|
svg.querySelector("text")?.setAttribute("color", "red");
|
||||||
title = svg.querySelector("title").innerHTML;
|
title = svg.querySelector("title")?.innerHTML ?? "";
|
||||||
} else {
|
} else {
|
||||||
svg.insertBefore(style, svg.children[0]);
|
svg.insertBefore(style, svg.children[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue