Skip to content

Commit 5ceec1d

Browse files
committed
precalculate a few more regexps in svg_text_utils
1 parent cb8c331 commit 5ceec1d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib/svg_text_utils.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ function getSize(_selection, _dimension) {
2323
return _selection.node().getBoundingClientRect()[_dimension];
2424
}
2525

26+
var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
27+
2628
exports.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 = /(<|&lt;|&#60;)/g;
144+
var GT_MATCH = /(>|&gt;|&#62;)/g;
145+
141146
function cleanEscapesForTex(s) {
142-
return s.replace(/(<|&lt;|&#60;)/g, '\\lt ')
143-
.replace(/(>|&gt;|&#62;)/g, '\\gt ');
147+
return s.replace(LT_MATCH, '\\lt ')
148+
.replace(GT_MATCH, '\\gt ');
144149
}
145150

146151
function texToSVG(_texString, _config, _callback) {

0 commit comments

Comments
 (0)