@@ -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
+ this . AppendMathElements ( 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
+ { this . AppendMathElements ( 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
+ { this . AppendMathElements ( mathArray , element . getElementsByTagName ( ns . name + ":math" ) ) }
74
75
}
75
76
} catch ( err ) { }
76
77
} else {
@@ -82,12 +83,19 @@ 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
+ { this . AppendMathElements ( mathArray , element . getElementsByTagName ( attr . nodeName . substr ( 6 ) + ":math" ) ) }
86
87
}
87
88
}
88
89
}
90
+ this . ProcessMathArray ( mathArray ) ;
89
91
} ,
90
92
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
+
91
99
ProcessMathArray : function ( math ) {
92
100
var i ;
93
101
if ( math . length ) {
@@ -104,6 +112,7 @@ MathJax.Extension.mml2jax = {
104
112
105
113
ProcessMath : function ( math ) {
106
114
var parent = math . parentNode ;
115
+ if ( ! parent || parent . className === "MathJax_Preview" ) return ;
107
116
var script = document . createElement ( "script" ) ;
108
117
script . type = "math/mml" ;
109
118
parent . insertBefore ( script , math ) ;
@@ -123,6 +132,7 @@ MathJax.Extension.mml2jax = {
123
132
124
133
ProcessMathFlattened : function ( math ) {
125
134
var parent = math . parentNode ;
135
+ if ( ! parent || parent . className === "MathJax_Preview" ) return ;
126
136
var script = document . createElement ( "script" ) ;
127
137
script . type = "math/mml" ;
128
138
parent . insertBefore ( script , math ) ;
@@ -188,7 +198,7 @@ MathJax.Extension.mml2jax = {
188
198
if ( preview === "mathml" ) {
189
199
isNodePreview = true ;
190
200
// 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 ) }
192
202
}
193
203
if ( preview === "alttext" || preview === "altimg" ) {
194
204
isNodePreview = true ;
0 commit comments