mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: keep tabs that are code content under a block quote (#4217)
* fix: keep tabs that are code content under a block quote After ">", an optional space is part of the marker; tabs after that space belong to the line content (e.g. fenced code) and must not be expanded. Tabs with no leading space are still expanded so indented code under a quote keeps working. Fixes #4184 * test: move the block quote tab case to a renderExact spec
This commit is contained in:
+10
-1
@@ -270,7 +270,16 @@ export class _Tokenizer<ParserOutput = string, RendererOutput = string> {
|
||||
// After a space the marker consumes it whole, so later tabs stay literal.
|
||||
.replace(
|
||||
this.rules.other.blockquoteMarkerWhitespace,
|
||||
(_, marker: string, whitespace: string) => marker + expandTabs(whitespace, marker.length),
|
||||
(_: string, marker: string, whitespace: string) => {
|
||||
// The optional space after ">" is marker; anything after that is
|
||||
// content (e.g. a tab that opens a fenced code line) and must not
|
||||
// be expanded. Tabs with no leading space are structural and are
|
||||
// expanded so indented code under the quote still works.
|
||||
if (whitespace.startsWith(' ')) {
|
||||
return marker + ' ' + whitespace.slice(1);
|
||||
}
|
||||
return marker + expandTabs(whitespace, marker.length);
|
||||
},
|
||||
)
|
||||
// precede setext continuation with 4 spaces so it isn't a setext
|
||||
.replace(this.rules.other.blockquoteSetextReplace, '\n $1')
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<blockquote>
|
||||
<pre><code class="language-python">class P:
|
||||
name: str
|
||||
</code></pre>
|
||||
</blockquote>
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
renderExact: true
|
||||
---
|
||||
> ```python
|
||||
> class P:
|
||||
> name: str
|
||||
> ```
|
||||
Reference in New Issue
Block a user