From c4627ff8ca4ae8d27fd3d5d6a9b708633f225d3b Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 13 Jun 2019 11:15:21 -0400 Subject: [PATCH] Check that svg and html elements exist before trying to use them (in case the input jax fails). See issue #441. --- lib/main.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 073a9e94..dd2a0593 100644 --- a/lib/main.js +++ b/lib/main.js @@ -620,6 +620,7 @@ function AddError(message,nopush) { function GetMML(result) { if (!data.mml && !data.mmlNode) return; var jax = MathJax.Hub.getAllJax()[0]; + if (!jax) return; if (data.speakText && !jax.root.alttext) { jax.root.alttext = result.speakText; var attrNames = jax.root.attrNames; @@ -643,10 +644,11 @@ function GetMML(result) { function GetSpeech(result) { if (!data.speakText) return; result.speakText = "Equation"; - if (data.format !== "MathML") result.speakText = data.math; - else { + if (data.format !== "MathML") { + result.speakText = data.math; + } else { var jax = MathJax.Hub.getAllJax()[0]; - if (jax.root.alttext) result.speakText = jax.root.alttext; + if (jax && jax.root.alttext) result.speakText = jax.root.alttext; } } @@ -658,7 +660,7 @@ function GetHTML(result) { if (!data.html && !data.htmlNode) return; var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return; var script = jax.SourceElement(), html = script.previousSibling; - + if (!html) return; // add speech text if there isn't one if (data.speakText){ var labelTarget = html.querySelector('.mjx-math'); @@ -695,6 +697,7 @@ function GetSVG(result) { var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return; var script = jax.SourceElement(), svg = script.previousSibling.getElementsByTagName("svg")[0]; + if (!svg) return; svg.setAttribute("xmlns","http://www.w3.org/2000/svg"); //