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.

Signed-off-by: physikerwelt <wiki@physikerwelt.de>

Change-Id: I0e2071aebee4e524960b01c4a5a10e49b5520846
This commit is contained in:
Davide P. Cervone 2013-11-21 08:49:43 -05:00 committed by physikerwelt
parent f4b6e74d64
commit d463f88c18

View file

@ -53,12 +53,11 @@ MathJax.Extension.mml2jax = {
// //
// Handle all math tags with no namespaces // 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 // Handle math with namespaces in XHTML
// //
if (element.getElementsByTagNameNS) this.PushMathElements(mathArray,element,"math",this.MMLnamespace);
{mathArray.push.apply(mathArray,element.getElementsByTagNameNS(this.MMLnamespace,"math"))}
// //
// Handle math with namespaces in HTML // Handle math with namespaces in HTML
// //
@ -71,7 +70,7 @@ MathJax.Extension.mml2jax = {
for (i = 0, m = document.namespaces.length; i < m; i++) { for (i = 0, m = document.namespaces.length; i < m; i++) {
var ns = document.namespaces[i]; var ns = document.namespaces[i];
if (ns.urn === this.MMLnamespace) if (ns.urn === this.MMLnamespace)
{mathArray.push.apply(mathArray,element.getElementsByTagName(ns.name+":math"))} {this.PushMathElements(mathArray,element,ns.name+":math")}
} }
} catch (err) {} } catch (err) {}
} else { } else {
@ -83,13 +82,28 @@ MathJax.Extension.mml2jax = {
for (i = 0, m = html.attributes.length; i < m; i++) { for (i = 0, m = html.attributes.length; i < m; i++) {
var attr = html.attributes[i]; var attr = html.attributes[i];
if (attr.nodeName.substr(0,6) === "xmlns:" && attr.nodeValue === this.MMLnamespace) 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); 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) { ProcessMathArray: function (math) {
var i, m = math.length; var i, m = math.length;
if (m) { if (m) {