cmark

My personal build of CMark ✏️

Commit
ac8529c9f55da7fdc1186e3f34313cf411de6e71
Parent
1ffcc1d908a4b3f8c6e0c0ca0af7cc6cc4c28331
Author
John MacFarlane <jgm@berkeley.edu>
Date

Re-added backtracking and memoization.

Gives better results for things like

**foo*

Diffstat

1 file changed, 11 insertions, 19 deletions

Status File Name N° Changes Insertions Deletions
Modified js/stmd.js 30 11 19
diff --git a/js/stmd.js b/js/stmd.js
@@ -289,6 +289,7 @@
         }
 
         this.pos += numdelims;
+        var delimpos = this.pos;
 
         var next_inline;
         var first = [];
@@ -472,36 +473,31 @@
             }
 
         }
+        this.pos = startpos;
+        return null;
 
         switch (state) {
         case 1: // ***a
-            return [{t: 'Str', c: c+c+c}].concat(first);
+            return [{t: 'Emph', c: [{t: 'Str', c: c}]}].concat(first);
         case 2: // **a
             return [{t: 'Str', c: c+c}].concat(first);
         case 3: // *a
             return [{t: 'Str', c: c}].concat(first);
         case 4: // ***a**b
         case 6: // ***a** b
-            return [{t: 'Str', c: c+c+c}]
-                .concat(first,
-                        [{t: 'Str', c: c+c}],
-                        second);
+            return [{t: 'Strong', c:
+                     [{t: 'Str', c: c}].concat(first)}].concat(second);
         case 5: // ***a*b
         case 7: // ***a* b
-            return [{t: 'Str', c: c+c+c}]
-                .concat(first,
-                        [{t: 'Str', c: c}],
-                        second);
+            return [{t: 'Emph', c:
+                     [{t: 'Str', c: c+c}].concat(first)}].concat(second);
         case 8: // **a *b
             return [{t: 'Str', c: c+c}]
                 .concat(first,
                         [{t: 'Str', c: c}],
                         second);
         case 9: // *a **b
-            return [{t: 'Str', c: c}]
-                .concat(first,
-                        [{t: 'Str', c: c+c}],
-                        second);
+            return [{t: 'Emph', c: first.concat([{t: 'Str', c: c}])}].concat(second);
         default:
             console.log("Unknown state, parseEmphasis");
             // shouldn't happen
@@ -783,13 +779,11 @@
     // and returning the inline parsed.
     var parseInline = function() {
         var startpos = this.pos;
-        /*
         var memoized = this.memo[startpos];
         if (memoized) {
             this.pos = memoized.endpos;
             return memoized.inline;
         }
-        */
         var c = this.peek();
         if (!c) {
             return null;
@@ -830,12 +824,10 @@
             this.pos += 1;
             res = [{t: 'Str', c: c}];
         }
-        /*
         if (res) {
             this.memo[startpos] = { inline: res,
                                     endpos: this.pos };
         }
-         */
         return res;
     };
 
@@ -844,7 +836,7 @@
         this.subject = s;
         this.pos = 0;
         this.refmap = refmap || {};
-        // this.memo = {};
+        this.memo = {};
         this.last_emphasis_closer = null;
         var inlines = [];
         var next_inline;
@@ -862,7 +854,7 @@
             last_emphasis_closer: null,  // used by parseEmphasis method
             pos: 0,
             refmap: {},
-            // memo: {},
+            memo: {},
             match: match,
             peek: peek,
             spnl: spnl,