cmark

My personal build of CMark ✏️

Commit
cc6bb4bd3cf241835cd31066bc06d005684459ac
Parent
c9994effcff67d4fddab23c2364218a09e807768
Author
John MacFarlane <jgm@berkeley.edu>
Date

Defer closing of fenced code blocks.

Instead of closing a fenced code block when we see the closing fence, we set fenceLength to -1, which then signals the code that checks for block enders that it is time to close the block.

This allows us to process a blank line after the fenced code and set _lastLineBlank appropriately.

Addresses #285 for JS implementation.

Diffstat

1 file changed, 13 insertions, 6 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 19 13 6
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
@@ -308,11 +308,18 @@ var incorporateLine = function(ln) {
 
         case 'CodeBlock':
             if (container._isFenced) { // fenced
-                // skip optional spaces of fence offset
-                i = container._fenceOffset;
-                while (i > 0 && ln.charCodeAt(offset) === C_SPACE) {
-                    offset++;
-                    i--;
+                if (container._fenceLength === -1) {
+                    all_matched = false;
+                    if (blank) {
+                        container._lastLineBlank = true;
+                    }
+                } else {
+                    // skip optional spaces of fence offset
+                    i = container._fenceOffset;
+                    while (i > 0 && ln.charCodeAt(offset) === C_SPACE) {
+                        offset++;
+                        i--;
+                    }
                 }
             } else { // indented
                 if (indent >= CODE_INDENT) {
@@ -533,7 +540,7 @@ var incorporateLine = function(ln) {
                          ln.slice(first_nonspace).match(reClosingCodeFence));
                 if (match && match[0].length >= container._fenceLength) {
                     // don't add closing fence to container; instead, close it:
-                    this.finalize(container, this.lineNumber);
+                    container._fenceLength = -1; // -1 means we've passed closer
                 } else {
                     this.addLine(ln, offset);
                 }