Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,35 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
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) {
Expand Down
1 change: 1 addition & 0 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+/,
Expand Down
67 changes: 67 additions & 0 deletions test/specs/new/list_lazy_after_empty_or_non_paragraph_block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<ul>
<li><ul>
<li></li>
</ul>
</li>
</ul>
<p>not in the list</p>
<ol>
<li><ul>
<li></li>
</ul>
</li>
</ol>
<p>not in the list</p>
<ul>
<li><ol>
<li></li>
</ol>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><blockquote>
</blockquote>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><ul>
<li><h1>heading</h1>
</li>
</ul>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><ul>
<li><pre><code></code></pre>
</li>
</ul>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><ul>
<li><hr>
</li>
</ul>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><ul>
<li><pre><code>code
</code></pre>
</li>
</ul>
</li>
</ul>
<p>not in the list</p>
<ul>
<li><ul>
<li>item
in the nested item</li>
</ul>
</li>
</ul>
26 changes: 26 additions & 0 deletions test/specs/new/list_lazy_after_empty_or_non_paragraph_block.md
Original file line number Diff line number Diff line change
@@ -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
Loading