diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-09 21:46:06 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-09 21:46:06 -0800 |
commit | 0e8c3fc0f2878ad45023dc53d1fbbc53b82b94d2 (patch) | |
tree | 162aa103c04ef2e7bf991b2813f8de35a1a89efb /js/lib | |
parent | 6f345edbcfbf2770ccdfb70c2a157eaf0e2930dd (diff) |
Improved unescapeString performance.
Diffstat (limited to 'js/lib')
-rw-r--r-- | js/lib/inlines.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js index f27a7e7..405c6c9 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -68,14 +68,23 @@ var reEntityHere = new RegExp('^' + ENTITY, 'i'); var reEntity = new RegExp(ENTITY, 'gi'); +var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi'); + // Matches a string of non-special characters. var reMain = /^[^\n`\[\]\\!<&*_]+/m; +var unescapeChar = function(s) { + if (s[0] === '\\') { + return s[1]; + } else { + return entityToChar(s); + } +}; + // Replace entities and backslash escapes with literal characters. var unescapeString = function(s) { "use strict"; - return s.replace(reAllEscapedChar, '$1') - .replace(reEntity, entityToChar); + return s.replace(reEntityOrEscapedChar, unescapeChar); }; // Normalize reference label: collapse internal whitespace |