fix: preserve trailing blank lines in fenced code (#4200)

This commit is contained in:
lfhwnqe
2026-11-16 09:26:02 -07:00
committed by GitHub
parent b535046bf5
commit 7499eb3a23
5 changed files with 33 additions and 1 deletions
+6 -1
View File
@@ -185,7 +185,12 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
const cap = this.rules.block.fences.exec(src);
if (cap) {
const raw = cap[0];
const text = indentCodeCompensation(raw, cap[3] || '', this.rules);
let text = indentCodeCompensation(raw, cap[3] || '', this.rules);
// The fence pattern consumes the final content newline outside the capture.
// Keep it when the captured content ends in a blank line.
if (cap[3] !== undefined && (text === '' || text.endsWith('\n'))) {
text += '\n';
}
return {
type: 'code',
@@ -0,0 +1,2 @@
<pre><code>
</code></pre>
@@ -0,0 +1,6 @@
---
renderExact: true
---
```
```
@@ -0,0 +1,9 @@
<ul>
<li>a</li>
<li><pre><code>b
</code></pre>
</li>
<li>c</li>
</ul>
@@ -0,0 +1,10 @@
---
renderExact: true
---
- a
- ```
b
```
- c