cmark

My personal build of CMark ✏️

Commit
ec18344cf02a03c0c3a2254c72b7efc2d378d71a
Parent
9ff768886050b8a62cba180d9c2d575c0fe82364
Author
John MacFarlane <jgm@berkeley.edu>
Date

Another "test before replace" optimization.

Diffstat

1 file changed, 7 insertions, 1 deletion

Status File Name N° Changes Insertions Deletions
Modified js/lib/inlines.js 8 7 1
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
@@ -65,6 +65,8 @@ var reEntityHere = new RegExp('^' + ENTITY, 'i');
 
 var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi');
 
+var reBackslashOrAmp = /[\\&]/;
+
 var reTicks = new RegExp('`+');
 
 var reTicksHere = new RegExp('^`+');
@@ -102,7 +104,11 @@ var unescapeChar = function(s) {
 // Replace entities and backslash escapes with literal characters.
 var unescapeString = function(s) {
     "use strict";
-    return s.replace(reEntityOrEscapedChar, unescapeChar);
+    if (reBackslashOrAmp.test(s)) {
+        return s.replace(reEntityOrEscapedChar, unescapeChar);
+    } else {
+        return s;
+    }
 };
 
 // Normalize reference label: collapse internal whitespace