cmark

My personal build of CMark ✏️

Commit
0e8c3fc0f2878ad45023dc53d1fbbc53b82b94d2
Parent
6f345edbcfbf2770ccdfb70c2a157eaf0e2930dd
Author
John MacFarlane <jgm@berkeley.edu>
Date

Improved unescapeString performance.

Diffstat

1 file changed, 11 insertions, 2 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/inlines.js 13 11 2
diff --git 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