mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: preserve trailing blank lines in fenced code (#4200)
This commit is contained in:
+6
-1
@@ -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
|
||||
Reference in New Issue
Block a user