diff --git a/lib/rules_block/list.js b/lib/rules_block/list.js index 6569cec..32a2d72 100644 --- a/lib/rules_block/list.js +++ b/lib/rules_block/list.js @@ -98,43 +98,73 @@ function markTightParagraphs(state, idx) { module.exports = function list(state, startLine, endLine, silent) { - var nextLine, + var ch, + contentStart, + i, + indent, + indentAfterMarker, initial, + isOrdered, + itemLines, + l, + listLines, + listTokIdx, + markerCharCode, + markerValue, + max, + nextLine, offset, - indent, - oldTShift, oldIndent, oldLIndent, - oldTight, oldParentType, - start, - posAfterMarker, - ch, + oldTShift, + oldTight, pos, - max, - indentAfterMarker, - markerValue, - markerCharCode, - isOrdered, - contentStart, - listTokIdx, + posAfterMarker, prevEmptyEnd, - listLines, - itemLines, - tight = true, + start, + terminate, terminatorRules, token, - i, l, terminate; + isTerminatingParagraph = false, + tight = true; + + // limit conditions when list can interrupt + // a paragraph (validation mode only) + if (silent && state.parentType === 'paragraph') { + // Next list item should still terminate previous list item; + // + // This code can fail if plugins use blkIndent as well as lists, + // but I hope the spec gets fixed long before that happens. + // + if (state.tShift[startLine] >= state.blkIndent) { + isTerminatingParagraph = true; + } + } // Detect list type and position after marker if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) { isOrdered = true; + start = state.bMarks[startLine] + state.tShift[startLine]; + markerValue = Number(state.src.substr(start, posAfterMarker - start - 1)); + + // If we're starting a new ordered list right after + // a paragraph, it should start with 1. + if (isTerminatingParagraph && markerValue !== 1) return false; + } else if ((posAfterMarker = skipBulletListMarker(state, startLine)) >= 0) { isOrdered = false; + } else { return false; } + // If we're starting a new unordered list right after + // a paragraph, first line should not be empty. + if (isTerminatingParagraph) { + if (state.skipSpaces(posAfterMarker) >= state.eMarks[startLine]) return false; + } + // We should terminate list on style change. Remember first one to compare. markerCharCode = state.src.charCodeAt(posAfterMarker - 1); @@ -145,8 +175,6 @@ module.exports = function list(state, startLine, endLine, silent) { listTokIdx = state.tokens.length; if (isOrdered) { - start = state.bMarks[startLine] + state.tShift[startLine]; - markerValue = Number(state.src.substr(start, posAfterMarker - start - 1)); token = state.push('ordered_list_open', 'ol', 1); if (markerValue !== 1) { token.attrs = [ [ 'start', markerValue ] ]; diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index 21c6220..3dcb8d5 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -18,69 +18,3 @@ error: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4214 - -. -foo -* - -foo -1. -. -

foo -*

-

foo -1.

-. - -error: - -

foo

- -

foo

-
    -
  1. -
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 4866 - -. -The number of windows in my house is -14. The number of doors is 6. -. -

The number of windows in my house is -14. The number of doors is 6.

-. - -error: - -

The number of windows in my house is

-
    -
  1. The number of doors is 6.
  2. -
- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 6137 - -. -*foo bar -* -. -

*foo bar -*

-. - -error: - -

*foo bar

- - - diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index c04ffa9..ec87519 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -3373,6 +3373,22 @@ src line: 4204 . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4214 + +. +foo +* + +foo +1. +. +

foo +*

+

foo +1.

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4236 @@ -3716,6 +3732,17 @@ Foo . +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 4866 + +. +The number of windows in my house is +14. The number of doors is 6. +. +

The number of windows in my house is +14. The number of doors is 6.

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 4876 @@ -4708,6 +4735,17 @@ src line: 6128

*foo bar *

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 6137 + +. +*foo bar +* +. +

*foo bar +*

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 6150