Skip to content

Commit b6d6cdd

Browse files
committed
Handle restarts during toMathML(), even though they are rare.
1 parent e8b8186 commit b6d6cdd

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/mj-page.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ function TypesetDone() {
520520
// Clean up the SVG for use in a page without MathJax.
521521
//
522522
function AdjustSVG() {
523-
var nodes, i;
523+
var nodes, i, callback;
524524
if (data.renderer === "SVG" || data.renderer === "IMG" || data.renderer === "PNG") {
525525
//
526526
// Fix missing xlink namespace on href's
@@ -563,20 +563,23 @@ function AdjustSVG() {
563563
//
564564
// Add speech text, if needed
565565
//
566-
if (data.speakText) {GetSpeech()}
566+
if (data.speakText) {callback = GetSpeech()}
567567
}
568+
return callback;
568569
}
569570

570571
//
571572
// Add the speech text and mark the SVG appropriately
572573
//
573574
function GetSpeech() {
574-
var nodes = document.querySelectorAll(".MathJax_SVG svg");
575-
for (var j = nodes.length-1; j >= 0; j--) {
576-
var svg = nodes[j];
577-
var jax = MathJax.Hub.getJaxFor(svg);
578-
var mml = jax.root.toMathML("",jax); // ### FIXME: should trap restarts here
579-
var id = jax.inputID;
575+
var nodes = document.querySelectorAll(".MathJax_SVG svg"), queue;
576+
var SPEAK = function (svg) {
577+
var jax = MathJax.Hub.getJaxFor(svg), id = jax.inputID, mml;
578+
try {mml = jax.root.toMathML('',jax)} catch(err) {
579+
if (!err.restart) {throw err;} // an actual error
580+
if (!queue) {queue = MathJax.Callback.Queue()}
581+
return queue.Push(err.restart,window.Array(SPEAK,svg));
582+
}
580583
svg.setAttribute("role","math");
581584
svg.setAttribute("aria-labelledby",id+"-Title "+id+"-Desc");
582585
for (var i = 0, m = svg.childNodes.length; i < m; i++)
@@ -586,6 +589,8 @@ function GetSpeech() {
586589
node = MathJax.HTML.Element("title",{id:id+"-Title"},["Equation"]);
587590
svg.insertBefore(node,svg.firstChild);
588591
}
592+
for (var i = nodes.length-1; i >= 0; i--) SPEAK(nodes[i]);
593+
if (queue) return queue.Push(function () {}); // wait for all the queue entries to finish
589594
}
590595

591596
//

0 commit comments

Comments
 (0)