@@ -48,12 +48,21 @@ MathJax.Extension.asciimath2jax = {
48
48
// are ignored. Note that this is a regular expression,
49
49
// so be sure to quote any regexp special characters
50
50
51
- preview : "AsciiMath" // set to "none" to not insert MathJax_Preview spans
51
+ preview : "AsciiMath" // set to "none" to not insert MathJax_Preview spans
52
52
// or set to an array specifying an HTML snippet
53
53
// to use the same preview for every equation.
54
54
55
55
} ,
56
56
57
+ //
58
+ // Tags to ignore when searching for AsciiMath in the page
59
+ //
60
+ ignoreTags : {
61
+ br : ( MathJax . Hub . Browser . isMSIE && document . documentMode < 9 ? "\n" : " " ) ,
62
+ wbr : "" ,
63
+ "#comment" : ""
64
+ } ,
65
+
57
66
PreProcess : function ( element ) {
58
67
if ( ! this . configured ) {
59
68
this . config = MathJax . Hub . CombineConfig ( "asciimath2jax" , this . config ) ;
@@ -132,8 +141,7 @@ MathJax.Extension.asciimath2jax = {
132
141
if ( this . search . matched ) { element = this . encloseMath ( element ) }
133
142
if ( element ) {
134
143
do { prev = element ; element = element . nextSibling }
135
- while ( element && ( element . nodeName . toLowerCase ( ) === 'br' ||
136
- element . nodeName . toLowerCase ( ) === '#comment' ) ) ;
144
+ while ( element && this . ignoreTags [ element . nodeName . toLowerCase ( ) ] != null ) ;
137
145
if ( ! element || element . nodeName !== '#text' ) { return prev }
138
146
}
139
147
}
@@ -172,25 +180,24 @@ MathJax.Extension.asciimath2jax = {
172
180
} ,
173
181
174
182
encloseMath : function ( element ) {
175
- var search = this . search , close = search . close , CLOSE , math ;
183
+ var search = this . search , close = search . close , CLOSE , math , next ;
176
184
if ( search . cpos === close . length ) { close = close . nextSibling }
177
185
else { close = close . splitText ( search . cpos ) }
178
186
if ( ! close ) { CLOSE = close = MathJax . HTML . addText ( search . close . parentNode , "" ) }
179
187
search . close = close ;
180
188
math = ( search . opos ? search . open . splitText ( search . opos ) : search . open ) ;
181
- while ( math . nextSibling && math . nextSibling !== close ) {
182
- if ( math . nextSibling . nodeValue !== null ) {
183
- if ( math . nextSibling . nodeName === "#comment" ) {
184
- math . nodeValue += math . nextSibling . nodeValue . replace ( / ^ \[ C D A T A \[ ( ( .| \n | \r ) * ) \] \] $ / , "$1" ) ;
189
+ while ( ( next = math . nextSibling ) && next !== close ) {
190
+ if ( next . nodeValue !== null ) {
191
+ if ( next . nodeName === "#comment" ) {
192
+ math . nodeValue += next . nodeValue . replace ( / ^ \[ C D A T A \[ ( ( .| \n | \r ) * ) \] \] $ / , "$1" ) ;
185
193
} else {
186
194
math . nodeValue += math . nextSibling . nodeValue ;
187
195
}
188
- } else if ( this . msieNewlineBug ) {
189
- math . nodeValue += ( math . nextSibling . nodeName . toLowerCase ( ) === "br" ? "\n" : " " ) ;
190
196
} else {
191
- math . nodeValue += " " ;
197
+ var ignore = this . ignoreTags [ next . nodeName . toLowerCase ( ) ] ;
198
+ math . nodeValue += ( ignore == null ? " " : ignore ) ;
192
199
}
193
- math . parentNode . removeChild ( math . nextSibling ) ;
200
+ math . parentNode . removeChild ( next ) ;
194
201
}
195
202
var AM = math . nodeValue . substr ( search . olen , math . nodeValue . length - search . olen - search . clen ) ;
196
203
math . parentNode . removeChild ( math ) ;
@@ -207,11 +214,13 @@ MathJax.Extension.asciimath2jax = {
207
214
} ,
208
215
209
216
createPreview : function ( mode , asciimath ) {
217
+ var previewClass = MathJax . Hub . config . preRemoveClass ;
210
218
var preview = this . config . preview ;
211
219
if ( preview === "none" ) return ;
220
+ if ( ( this . search . close . previousSibling || { } ) . className === previewClass ) return ;
212
221
if ( preview === "AsciiMath" ) { preview = [ this . filterPreview ( asciimath ) ] }
213
222
if ( preview ) {
214
- preview = MathJax . HTML . Element ( "span" , { className :MathJax . Hub . config . preRemoveClass } , preview ) ;
223
+ preview = MathJax . HTML . Element ( "span" , { className :previewClass } , preview ) ;
215
224
this . insertNode ( preview ) ;
216
225
}
217
226
} ,
@@ -224,9 +233,7 @@ MathJax.Extension.asciimath2jax = {
224
233
return script ;
225
234
} ,
226
235
227
- filterPreview : function ( asciimath ) { return asciimath } ,
228
-
229
- msieNewlineBug : ( MathJax . Hub . Browser . isMSIE && ( document . documentMode || 0 ) < 9 )
236
+ filterPreview : function ( asciimath ) { return asciimath }
230
237
231
238
} ;
232
239
0 commit comments