Skip to content

Commit 88c26b3

Browse files
committed
Merge pull request #609 from fred-wang/preview
Preview
2 parents 36895de + a9d8123 commit 88c26b3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

unpacked/extensions/mml2jax.js

Lines changed: 13 additions & 9 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+
mathArray.push.apply(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+
{mathArray.push.apply(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+
{mathArray.push.apply(mathArray,element.getElementsByTagName(ns.name+":math"))}
7475
}
7576
} catch (err) {}
7677
} else {
@@ -82,28 +83,30 @@ 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+
{mathArray.push.apply(mathArray,element.getElementsByTagName(attr.nodeName.substr(6)+":math"))}
8687
}
8788
}
8889
}
90+
this.ProcessMathArray(mathArray);
8991
},
9092

9193
ProcessMathArray: function (math) {
92-
var i;
93-
if (math.length) {
94+
var i, m = math.length;
95+
if (m) {
9496
if (this.MathTagBug) {
95-
for (i = math.length-1; i >= 0; i--) {
97+
for (i = 0; i < m; i++) {
9698
if (math[i].nodeName === "MATH") {this.ProcessMathFlattened(math[i])}
9799
else {this.ProcessMath(math[i])}
98100
}
99101
} else {
100-
for (i = math.length-1; i >= 0; i--) {this.ProcessMath(math[i])}
102+
for (i = 0; i < m; i++) {this.ProcessMath(math[i])}
101103
}
102104
}
103105
},
104106

105107
ProcessMath: function (math) {
106108
var parent = math.parentNode;
109+
if (!parent || parent.className === MathJax.Hub.config.preRemoveClass) return;
107110
var script = document.createElement("script");
108111
script.type = "math/mml";
109112
parent.insertBefore(script,math);
@@ -123,6 +126,7 @@ MathJax.Extension.mml2jax = {
123126

124127
ProcessMathFlattened: function (math) {
125128
var parent = math.parentNode;
129+
if (!parent || parent.className === MathJax.Hub.config.preRemoveClass) return;
126130
var script = document.createElement("script");
127131
script.type = "math/mml";
128132
parent.insertBefore(script,math);
@@ -188,7 +192,7 @@ MathJax.Extension.mml2jax = {
188192
if (preview === "mathml") {
189193
isNodePreview = true;
190194
// mathml preview does not work with IE < 9, so fallback to alttext.
191-
if (this.MathTagBug) {preview = "alttext"} else {preview = math}
195+
if (this.MathTagBug) {preview = "alttext"} else {preview = math.cloneNode(false)}
192196
}
193197
if (preview === "alttext" || preview === "altimg") {
194198
isNodePreview = true;

0 commit comments

Comments
 (0)