cmark

My personal build of CMark ✏️

Commit
de2a35a4dcb3b051df328ec2c204f08c77a5ad3d
Parent
7f4b2f7f3949f807d5dafe2219280a0f1419b0e2
Author
John MacFarlane <jgm@berkeley.edu>
Date

Simple fallback if we don't match emphasis.

The other approach led to wrong results on:

*hi _there*

Diffstat

1 file changed, 6 insertions, 25 deletions

Status File Name N° Changes Insertions Deletions
Modified js/stmd.js 31 6 25
diff --git a/js/stmd.js b/js/stmd.js
@@ -302,6 +302,9 @@
 
         this.pos += numdelims;
 
+        var fallbackpos = this.pos;
+        var fallback = Str(this.subject.slice(startpos, fallbackpos));
+
         var next_inline;
         var first = [];
         var second = [];
@@ -453,31 +456,9 @@
 
         }
 
-        switch (state) {
-        case 1: // ***a
-            return [Str(c+c+c)].concat(first);
-        case 2: // **a
-            return [Str(c+c)].concat(first);
-        case 3: // *a
-            return [Str(c)].concat(first);
-        case 4: // ***a**b
-        case 6: // ***a** b
-            return [Str(c+c+c)]
-                .concat(first, [Str(c+c)], second);
-        case 5: // ***a*b
-        case 7: // ***a* b
-            return [Str(c+c+c)]
-                .concat(first, [Str(c)], second);
-        case 8: // **a *b
-            return [Str(c+c)]
-                .concat(first, [Str(c)], second);
-        case 9: // *a **b
-            return [Str(c)]
-                .concat(first, [Str(c+c)], second);
-        default:
-            console.log("Unknown state, parseEmphasis");
-            // shouldn't happen
-        }
+        // we didn't match emphasis: fallback
+        this.pos = fallbackpos;
+        return [fallback];
 
     };