Skip to content

Commit aad3a6e

Browse files
committed
Try to fix test failures #557.
1 parent 412d366 commit aad3a6e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

unpacked/extensions/mml2jax.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ MathJax.Extension.mml2jax = {
4949
}
5050
if (typeof(element) === "string") {element = document.getElementById(element)}
5151
if (!element) {element = document.body}
52+
var mathArray = [];
5253
//
5354
// Handle all math tags with no namespaces
5455
//
55-
this.ProcessMathArray(element.getElementsByTagName("math"));
56+
this.AppendMathElements(mathArray,element.getElementsByTagName("math"));
5657
//
5758
// Handle math with namespaces in XHTML
5859
//
5960
if (element.getElementsByTagNameNS)
60-
{this.ProcessMathArray(element.getElementsByTagNameNS(this.MMLnamespace,"math"))}
61+
{this.AppendMathElements(mathArray,element.getElementsByTagNameNS(this.MMLnamespace,"math"))}
6162
//
6263
// Handle math with namespaces in HTML
6364
//
@@ -70,7 +71,7 @@ MathJax.Extension.mml2jax = {
7071
for (i = 0, m = document.namespaces.length; i < m; i++) {
7172
var ns = document.namespaces[i];
7273
if (ns.urn === this.MMLnamespace)
73-
{this.ProcessMathArray(element.getElementsByTagName(ns.name+":math"))}
74+
{this.AppendMathElements(mathArray,element.getElementsByTagName(ns.name+":math"))}
7475
}
7576
} catch (err) {}
7677
} else {
@@ -82,12 +83,19 @@ MathJax.Extension.mml2jax = {
8283
for (i = 0, m = html.attributes.length; i < m; i++) {
8384
var attr = html.attributes[i];
8485
if (attr.nodeName.substr(0,6) === "xmlns:" && attr.nodeValue === this.MMLnamespace)
85-
{this.ProcessMathArray(element.getElementsByTagName(attr.nodeName.substr(6)+":math"))}
86+
{this.AppendMathElements(mathArray,element.getElementsByTagName(attr.nodeName.substr(6)+":math"))}
8687
}
8788
}
8889
}
90+
this.ProcessMathArray(mathArray);
8991
},
9092

93+
AppendMathElements: function(mathArray, math) {
94+
if (math.length) {
95+
for (var i = math.length-1; i >= 0; i--) {mathArray.push(math[i])}
96+
}
97+
},
98+
9199
ProcessMathArray: function (math) {
92100
var i;
93101
if (math.length) {
@@ -104,6 +112,7 @@ MathJax.Extension.mml2jax = {
104112

105113
ProcessMath: function (math) {
106114
var parent = math.parentNode;
115+
if (!parent || parent.className === "MathJax_Preview") return;
107116
var script = document.createElement("script");
108117
script.type = "math/mml";
109118
parent.insertBefore(script,math);
@@ -123,6 +132,7 @@ MathJax.Extension.mml2jax = {
123132

124133
ProcessMathFlattened: function (math) {
125134
var parent = math.parentNode;
135+
if (!parent || parent.className === "MathJax_Preview") return;
126136
var script = document.createElement("script");
127137
script.type = "math/mml";
128138
parent.insertBefore(script,math);
@@ -188,7 +198,7 @@ MathJax.Extension.mml2jax = {
188198
if (preview === "mathml") {
189199
isNodePreview = true;
190200
// mathml preview does not work with IE < 9, so fallback to alttext.
191-
if (this.MathTagBug) {preview = "alttext"} else {preview = math}
201+
if (this.MathTagBug) {preview = "alttext"} else {preview = math.cloneNode(false)}
192202
}
193203
if (preview === "alttext" || preview === "altimg") {
194204
isNodePreview = true;

0 commit comments

Comments
 (0)