@@ -23,12 +23,14 @@ function getSize(_selection, _dimension) {
2323 return _selection . node ( ) . getBoundingClientRect ( ) [ _dimension ] ;
2424}
2525
26+ var FIND_TEX = / ( [ ^ $ ] * ) ( [ $ ] + [ ^ $ ] * [ $ ] + ) ( [ ^ $ ] * ) / ;
27+
2628exports . convertToTspans = function ( _context , gd , _callback ) {
2729 var str = _context . text ( ) ;
2830
2931 // Until we get tex integrated more fully (so it can be used along with non-tex)
3032 // allow some elements to prohibit it by attaching 'data-notex' to the original
31- var tex = ( ! _context . attr ( 'data-notex' ) ) && str . match ( / ( [ ^ $ ] * ) ( [ $ ] + [ ^ $ ] * [ $ ] + ) ( [ ^ $ ] * ) / ) ;
33+ var tex = ( ! _context . attr ( 'data-notex' ) ) && str . match ( FIND_TEX ) ;
3234 var parent = d3 . select ( _context . node ( ) . parentNode ) ;
3335 if ( parent . empty ( ) ) return ;
3436 var svgClass = ( _context . attr ( 'class' ) ) ? _context . attr ( 'class' ) . split ( ' ' ) [ 0 ] : 'text' ;
@@ -138,9 +140,12 @@ exports.convertToTspans = function(_context, gd, _callback) {
138140
139141// MathJax
140142
143+ var LT_MATCH = / ( < | & l t ; | & # 6 0 ; ) / g;
144+ var GT_MATCH = / ( > | & g t ; | & # 6 2 ; ) / g;
145+
141146function cleanEscapesForTex ( s ) {
142- return s . replace ( / ( < | & l t ; | & # 6 0 ; ) / g , '\\lt ' )
143- . replace ( / ( > | & g t ; | & # 6 2 ; ) / g , '\\gt ' ) ;
147+ return s . replace ( LT_MATCH , '\\lt ' )
148+ . replace ( GT_MATCH , '\\gt ' ) ;
144149}
145150
146151function texToSVG ( _texString , _config , _callback ) {
0 commit comments