@@ -49,15 +49,16 @@ MathJax.Extension.mml2jax = {
49
49
}
50
50
if ( typeof ( element ) === "string" ) { element = document . getElementById ( element ) }
51
51
if ( ! element ) { element = document . body }
52
+ var mathArray = [ ] ;
52
53
//
53
54
// Handle all math tags with no namespaces
54
55
//
55
- this . ProcessMathArray ( element . getElementsByTagName ( "math" ) ) ;
56
+ mathArray . push . apply ( mathArray , element . getElementsByTagName ( "math" ) ) ;
56
57
//
57
58
// Handle math with namespaces in XHTML
58
59
//
59
60
if ( element . getElementsByTagNameNS )
60
- { this . ProcessMathArray ( element . getElementsByTagNameNS ( this . MMLnamespace , "math" ) ) }
61
+ { mathArray . push . apply ( mathArray , element . getElementsByTagNameNS ( this . MMLnamespace , "math" ) ) }
61
62
//
62
63
// Handle math with namespaces in HTML
63
64
//
@@ -70,7 +71,7 @@ MathJax.Extension.mml2jax = {
70
71
for ( i = 0 , m = document . namespaces . length ; i < m ; i ++ ) {
71
72
var ns = document . namespaces [ i ] ;
72
73
if ( ns . urn === this . MMLnamespace )
73
- { this . ProcessMathArray ( element . getElementsByTagName ( ns . name + ":math" ) ) }
74
+ { mathArray . push . apply ( mathArray , element . getElementsByTagName ( ns . name + ":math" ) ) }
74
75
}
75
76
} catch ( err ) { }
76
77
} else {
@@ -82,28 +83,30 @@ MathJax.Extension.mml2jax = {
82
83
for ( i = 0 , m = html . attributes . length ; i < m ; i ++ ) {
83
84
var attr = html . attributes [ i ] ;
84
85
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" ) ) }
86
87
}
87
88
}
88
89
}
90
+ this . ProcessMathArray ( mathArray ) ;
89
91
} ,
90
92
91
93
ProcessMathArray : function ( math ) {
92
- var i ;
93
- if ( math . length ) {
94
+ var i , m = math . length ;
95
+ if ( m ) {
94
96
if ( this . MathTagBug ) {
95
- for ( i = math . length - 1 ; i >= 0 ; i -- ) {
97
+ for ( i = 0 ; i < m ; i ++ ) {
96
98
if ( math [ i ] . nodeName === "MATH" ) { this . ProcessMathFlattened ( math [ i ] ) }
97
99
else { this . ProcessMath ( math [ i ] ) }
98
100
}
99
101
} 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 ] ) }
101
103
}
102
104
}
103
105
} ,
104
106
105
107
ProcessMath : function ( math ) {
106
108
var parent = math . parentNode ;
109
+ if ( ! parent || parent . className === MathJax . Hub . config . preRemoveClass ) return ;
107
110
var script = document . createElement ( "script" ) ;
108
111
script . type = "math/mml" ;
109
112
parent . insertBefore ( script , math ) ;
@@ -123,6 +126,7 @@ MathJax.Extension.mml2jax = {
123
126
124
127
ProcessMathFlattened : function ( math ) {
125
128
var parent = math . parentNode ;
129
+ if ( ! parent || parent . className === MathJax . Hub . config . preRemoveClass ) return ;
126
130
var script = document . createElement ( "script" ) ;
127
131
script . type = "math/mml" ;
128
132
parent . insertBefore ( script , math ) ;
@@ -188,7 +192,7 @@ MathJax.Extension.mml2jax = {
188
192
if ( preview === "mathml" ) {
189
193
isNodePreview = true ;
190
194
// 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 ) }
192
196
}
193
197
if ( preview === "alttext" || preview === "altimg" ) {
194
198
isNodePreview = true ;
0 commit comments