diff --git a/lib/rules_block/code.js b/lib/rules_block/code.js index 74bc42a..470cb01 100644 --- a/lib/rules_block/code.js +++ b/lib/rules_block/code.js @@ -4,7 +4,7 @@ module.exports = function code(state, startLine, endLine/*, silent*/) { - var nextLine, last, token; + var nextLine, last, token, emptyLines = 0; if (state.sCount[startLine] - state.blkIndent < 4) { return false; } @@ -12,9 +12,20 @@ module.exports = function code(state, startLine, endLine/*, silent*/) { while (nextLine < endLine) { if (state.isEmpty(nextLine)) { + emptyLines++; + + // workaround for lists: 2 blank lines should terminate indented + // code block, but not fenced code block + if (emptyLines >= 2 && state.parentType === 'list') { + break; + } + nextLine++; continue; } + + emptyLines = 0; + if (state.sCount[nextLine] - state.blkIndent >= 4) { nextLine++; last = nextLine; @@ -23,7 +34,7 @@ module.exports = function code(state, startLine, endLine/*, silent*/) { break; } - state.line = nextLine; + state.line = last; token = state.push('code_block', 'code', 0); token.content = state.getLines(startLine, last, 4 + state.blkIndent, true); diff --git a/lib/rules_block/list.js b/lib/rules_block/list.js index bb28e6b..ea554f3 100644 --- a/lib/rules_block/list.js +++ b/lib/rules_block/list.js @@ -223,7 +223,18 @@ module.exports = function list(state, startLine, endLine, silent) { state.tShift[startLine] = contentStart - state.bMarks[startLine]; state.sCount[startLine] = offset; - state.md.block.tokenize(state, startLine, endLine, true); + if (contentStart >= max && state.isEmpty(startLine + 1)) { + // workaround for this case + // (list item is empty, list terminates before "foo"): + // ~~~~~~~~ + // - + // + // foo + // ~~~~~~~~ + state.line = Math.min(state.line + 2, endLine); + } else { + state.md.block.tokenize(state, startLine, endLine, true); + } // If any of list item is tight, mark list as tight if (!state.tight || prevEmptyEnd) { diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index f6b4edf..e69de29 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -1,57 +0,0 @@ -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 3777 - -. -- Foo - - bar - - - baz -. - -
  baz
-
-. - -error: - - - - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4044 - -. -- - - foo -. - -

foo

-. - -error: - - - - diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index ce47df5..71c0264 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -3060,6 +3060,28 @@ baz . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 3777 + +. +- Foo + + bar + + + baz +. + +
  baz
+
+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 3799 @@ -3272,6 +3294,20 @@ src line: 4016 . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4044 + +. +- + + foo +. + +

foo

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4058