aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-09 21:46:06 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-09 21:46:06 -0800
commit0e8c3fc0f2878ad45023dc53d1fbbc53b82b94d2 (patch)
tree162aa103c04ef2e7bf991b2813f8de35a1a89efb
parent6f345edbcfbf2770ccdfb70c2a157eaf0e2930dd (diff)
Improved unescapeString performance.
-rw-r--r--js/lib/inlines.js13
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