From cc6bb4bd3cf241835cd31066bc06d005684459ac Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 16 Jan 2015 21:43:39 -0800 Subject: 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. --- js/lib/blocks.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/lib/blocks.js b/js/lib/blocks.js index 9286e3a..c70af15 100644 --- 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); } -- cgit v1.2.3