fix: end a list item before a lazy line after an empty or non-paragraph nested block (#4183)

This commit is contained in:
Alperen Manas
2026-11-13 11:21:00 -07:00
committed by GitHub
parent 8a578e4c0c
commit ac2256e113
4 changed files with 114 additions and 5 deletions
+20 -5
View File
@@ -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) {
+1
View File
@@ -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]+/,
@@ -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>
@@ -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