fix: keep an indented code block after a list item paragraph (#4198)

* fix: keep an indented code block after a list item paragraph

In a list item, a paragraph line indented four or more spaces is lexed
as indented code and then merged back into the paragraph. The code
token also ran across the following blank line, so a real indented
code block after it was merged into the paragraph too.

* fix: continue list item text over indented lines in the text tokenizer
This commit is contained in:
Jay Hemnani
2026-11-16 11:03:07 -07:00
committed by GitHub
parent a0925cca02
commit b9e3824233
4 changed files with 37 additions and 3 deletions
+12 -3
View File
@@ -840,11 +840,20 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
text(src: string): Tokens.Text | undefined {
const cap = this.rules.block.text.exec(src);
if (cap) {
let raw = cap[0];
let text = cap[0];
// Indented code cannot interrupt the text, so indented lines continue it
// up to the next blank line
const continuation = this.rules.other.textIndentedContinuation.exec(src.slice(raw.length));
if (continuation) {
raw += continuation[0];
text += continuation[0].replace(this.rules.other.codeRemoveIndent, '');
}
return {
type: 'text',
raw: cap[0],
text: cap[0],
tokens: this.lexer.inline(cap[0]),
raw,
text,
tokens: this.lexer.inline(text),
};
}
}
+1
View File
@@ -60,6 +60,7 @@ export const other = {
multipleSpaceGlobal: /\s+/g,
blankLine: /^[ \t]*$/,
doubleBlankLine: /\n[ \t]*\n[ \t]*$/,
textIndentedContinuation: /^(?:\n(?: {4}| {0,3}\t)[ \t]*[^ \t\n][^\n]*)+/,
blockquoteStart: /^ {0,3}>/,
// Neutralize a lazy setext underline, including one with trailing tabs.
// CommonMark §4.3 allows those tabs on a real underline, so the same class
@@ -0,0 +1,13 @@
<ul>
<li><p>Run this
after wrapping</p>
<pre><code>npm install
</code></pre>
</li>
<li><p>a
b</p>
<pre><code>c
</code></pre>
<p>d</p>
</li>
</ul>
@@ -0,0 +1,11 @@
- Run this
after wrapping
npm install
- a
b
c
d