mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04: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);
|
||||
}
|
||||
|
||||
const output = globalThis.MathJax.tex2svg(input);
|
||||
const svg = output.children[0];
|
||||
let output: Element;
|
||||
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);
|
||||
}
|
||||
|
||||
let title = "";
|
||||
|
||||
if (svg.innerHTML.includes("data-mjx-error")) {
|
||||
svg.querySelector("rect").setAttribute("fill", "yellow");
|
||||
svg.querySelector("text").setAttribute("color", "red");
|
||||
title = svg.querySelector("title").innerHTML;
|
||||
svg.querySelector("rect")?.setAttribute("fill", "yellow");
|
||||
svg.querySelector("text")?.setAttribute("color", "red");
|
||||
title = svg.querySelector("title")?.innerHTML ?? "";
|
||||
} else {
|
||||
svg.insertBefore(style, svg.children[0]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue