diff --git a/src/Tokenizer.ts b/src/Tokenizer.ts index 5ddd4eb49c..ea4ac4a1ae 100644 --- a/src/Tokenizer.ts +++ b/src/Tokenizer.ts @@ -467,20 +467,35 @@ export class _Tokenizer { break; } + // The first line of an item always starts a block, which can be a + // nested list item or block quote. Look past their markers to the + // block a lazy line would continue. Tabs are left alone because + // their width depends on the column they start at. + let lastBlock = line; + if (!this.options.pedantic && !itemContents.includes('\n') && !line.includes('\t')) { + let marker; + while (!hrRegex.test(lastBlock) && (marker = this.rules.other.nestedBlockMarker.exec(lastBlock))) { + lastBlock = lastBlock.slice(marker[0].length); + } + if (!lastBlock.trim()) { // empty list item or block quote + break; + } + } + // paragraph continuation unless last line was a different block level element - if (line.replace(this.rules.other.tabCharGlobal, ' ').search(this.rules.other.nonSpaceChar) >= 4) { // indented code block + if (lastBlock.replace(this.rules.other.tabCharGlobal, ' ').search(this.rules.other.nonSpaceChar) >= 4) { // indented code block break; } - if (fencesBeginRegex.test(line)) { + if (fencesBeginRegex.test(lastBlock)) { break; } - if (headingBeginRegex.test(line)) { + if (headingBeginRegex.test(lastBlock)) { break; } - if (htmlBeginRegex.test(line)) { + if (htmlBeginRegex.test(lastBlock)) { break; } - if (hrRegex.test(line)) { + if (hrRegex.test(lastBlock)) { break; } if (!this.options.pedantic && !lineIsLazy) { diff --git a/src/rules.ts b/src/rules.ts index 45e2199206..8fe88ca584 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -64,6 +64,7 @@ export const other = { blockquoteSetextReplace: /\n {0,3}((?:=+|-+)[ \t]*)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, blockquoteMarkerWhitespace: /^( {0,3}>)(\t[ \t]*)/gm, + nestedBlockMarker: /^ {0,3}(?:(?:[*+-]|\d{1,9}[.)])(?: |$)|> ?)/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\][ \t]+\S/, listReplaceTask: /^\[[ xX]\][ \t]+/, diff --git a/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.html b/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.html new file mode 100644 index 0000000000..2b2bd568e5 --- /dev/null +++ b/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.html @@ -0,0 +1,67 @@ + +

not in the list

+
    +
    • +
    • +
    +
  1. +
+

not in the list

+ +

not in the list

+ +

not in the list

+ +

not in the list

+ +

not in the list

+ +

not in the list

+ +

not in the list

+ diff --git a/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.md b/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.md new file mode 100644 index 0000000000..1cf77e46f9 --- /dev/null +++ b/test/specs/new/list_lazy_after_empty_or_non_paragraph_block.md @@ -0,0 +1,26 @@ +- - +not in the list + +1. - +not in the list + +- 1. +not in the list + +- > +not in the list + +- - # heading +not in the list + +- - ``` +not in the list + +- - *** +not in the list + +- - code +not in the list + +- - item +in the nested item