@@ -53,12 +53,11 @@ MathJax.Extension.mml2jax = {
5353 //
5454 // Handle all math tags with no namespaces
5555 //
56- mathArray . push . apply ( mathArray , element . getElementsByTagName ( "math" ) ) ;
56+ this . PushMathElements ( mathArray , element , "math" ) ;
5757 //
5858 // Handle math with namespaces in XHTML
5959 //
60- if ( element . getElementsByTagNameNS )
61- { mathArray . push . apply ( mathArray , element . getElementsByTagNameNS ( this . MMLnamespace , "math" ) ) }
60+ this . PushMathElements ( mathArray , element , "math" , this . MMLnamespace ) ;
6261 //
6362 // Handle math with namespaces in HTML
6463 //
@@ -71,7 +70,7 @@ MathJax.Extension.mml2jax = {
7170 for ( i = 0 , m = document . namespaces . length ; i < m ; i ++ ) {
7271 var ns = document . namespaces [ i ] ;
7372 if ( ns . urn === this . MMLnamespace )
74- { mathArray . push . apply ( mathArray , element . getElementsByTagName ( ns . name + ":math" ) ) }
73+ { this . PushMathElements ( mathArray , element , ns . name + ":math" ) }
7574 }
7675 } catch ( err ) { }
7776 } else {
@@ -83,13 +82,28 @@ MathJax.Extension.mml2jax = {
8382 for ( i = 0 , m = html . attributes . length ; i < m ; i ++ ) {
8483 var attr = html . attributes [ i ] ;
8584 if ( attr . nodeName . substr ( 0 , 6 ) === "xmlns:" && attr . nodeValue === this . MMLnamespace )
86- { mathArray . push . apply ( mathArray , element . getElementsByTagName ( attr . nodeName . substr ( 6 ) + ":math" ) ) }
85+ { this . PushMathElements ( mathArray , element , attr . nodeName . substr ( 6 ) + ":math" ) }
8786 }
8887 }
8988 }
9089 this . ProcessMathArray ( mathArray ) ;
9190 } ,
9291
92+ PushMathElements : function ( array , element , name , namespace ) {
93+ var math , preview = MathJax . Hub . config . preRemoveClass ;
94+ if ( namespace ) {
95+ if ( ! element . getElementsByTagNameNS ) return ;
96+ math = element . getElementsByTagNameNS ( namespace , name ) ;
97+ } else {
98+ math = element . getElementsByTagName ( name ) ;
99+ }
100+ for ( var i = 0 , m = math . length ; i < m ; i ++ ) {
101+ var parent = math [ i ] . parentNode ;
102+ if ( parent && parent . className !== preview && ! math [ i ] . prefix === ! namespace )
103+ { array . push ( math [ i ] ) }
104+ }
105+ } ,
106+
93107 ProcessMathArray : function ( math ) {
94108 var i , m = math . length ;
95109 if ( m ) {
0 commit comments