commit d4fe0fdac26b4916c989bd40bc3796f728d543f1
parent 6a198f609279af235b3f9b41360169915ac68fa8
Author: Davide P. Cervone <dpvc@union.edu>
Date: Thu, 21 Nov 2013 08:49:43 -0500
Push math nodes onto mathArray individually to avoid problem in IE < 9 where push.apply doesn't work on a nodeList. Also, avoid duplicate elements in the array by checking for namespace prefixes. This needs to work for both HTML and XHTML. Resolves issue #672.
Diffstat:
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js
@@ -53,12 +53,11 @@ MathJax.Extension.mml2jax = {
//
// Handle all math tags with no namespaces
//
- mathArray.push.apply(mathArray,element.getElementsByTagName("math"));
+ this.PushMathElements(mathArray,element,"math");
//
// Handle math with namespaces in XHTML
//
- if (element.getElementsByTagNameNS)
- {mathArray.push.apply(mathArray,element.getElementsByTagNameNS(this.MMLnamespace,"math"))}
+ this.PushMathElements(mathArray,element,"math",this.MMLnamespace);
//
// Handle math with namespaces in HTML
//
@@ -71,7 +70,7 @@ MathJax.Extension.mml2jax = {
for (i = 0, m = document.namespaces.length; i < m; i++) {
var ns = document.namespaces[i];
if (ns.urn === this.MMLnamespace)
- {mathArray.push.apply(mathArray,element.getElementsByTagName(ns.name+":math"))}
+ {this.PushMathElements(mathArray,element,ns.name+":math")}
}
} catch (err) {}
} else {
@@ -83,13 +82,28 @@ MathJax.Extension.mml2jax = {
for (i = 0, m = html.attributes.length; i < m; i++) {
var attr = html.attributes[i];
if (attr.nodeName.substr(0,6) === "xmlns:" && attr.nodeValue === this.MMLnamespace)
- {mathArray.push.apply(mathArray,element.getElementsByTagName(attr.nodeName.substr(6)+":math"))}
+ {this.PushMathElements(mathArray,element,attr.nodeName.substr(6)+":math")}
}
}
}
this.ProcessMathArray(mathArray);
},
+ PushMathElements: function (array,element,name,namespace) {
+ var math, preview = MathJax.Hub.config.preRemoveClass;
+ if (namespace) {
+ if (!element.getElementsByTagNameNS) return;
+ math = element.getElementsByTagNameNS(namespace,name);
+ } else {
+ math = element.getElementsByTagName(name);
+ }
+ for (var i = 0, m = math.length; i < m; i++) {
+ var parent = math[i].parentNode;
+ if (parent && parent.className !== preview && !math[i].prefix === !namespace)
+ {array.push(math[i])}
+ }
+ },
+
ProcessMathArray: function (math) {
var i, m = math.length;
if (m) {