Skip to content

Commit c4627ff

Browse files
committed
Check that svg and html elements exist before trying to use them (in case the input jax fails). See issue #441.
1 parent 83b1d2f commit c4627ff

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ function AddError(message,nopush) {
620620
function GetMML(result) {
621621
if (!data.mml && !data.mmlNode) return;
622622
var jax = MathJax.Hub.getAllJax()[0];
623+
if (!jax) return;
623624
if (data.speakText && !jax.root.alttext) {
624625
jax.root.alttext = result.speakText;
625626
var attrNames = jax.root.attrNames;
@@ -643,10 +644,11 @@ function GetMML(result) {
643644
function GetSpeech(result) {
644645
if (!data.speakText) return;
645646
result.speakText = "Equation";
646-
if (data.format !== "MathML") result.speakText = data.math;
647-
else {
647+
if (data.format !== "MathML") {
648+
result.speakText = data.math;
649+
} else {
648650
var jax = MathJax.Hub.getAllJax()[0];
649-
if (jax.root.alttext) result.speakText = jax.root.alttext;
651+
if (jax && jax.root.alttext) result.speakText = jax.root.alttext;
650652
}
651653
}
652654

@@ -658,7 +660,7 @@ function GetHTML(result) {
658660
if (!data.html && !data.htmlNode) return;
659661
var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
660662
var script = jax.SourceElement(), html = script.previousSibling;
661-
663+
if (!html) return;
662664
// add speech text if there isn't one
663665
if (data.speakText){
664666
var labelTarget = html.querySelector('.mjx-math');
@@ -695,6 +697,7 @@ function GetSVG(result) {
695697
var jax = MathJax.Hub.getAllJax()[0]; if (!jax) return;
696698
var script = jax.SourceElement(),
697699
svg = script.previousSibling.getElementsByTagName("svg")[0];
700+
if (!svg) return;
698701
svg.setAttribute("xmlns","http://www.w3.org/2000/svg");
699702

700703
//

0 commit comments

Comments
 (0)