mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
fix: keep empty list after blockquote as a sibling block (#4004)
A blockquote followed by a bare list marker line (for example
`> foo\n-`) wrongly nested an empty list inside the blockquote.
The blockquote regex reuses the paragraph list-interrupt clause
` {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]`, whose trailing `[ \t]+[^ \t\n]`
requires content after the marker. A bare marker line therefore was
not seen as an interruption and got lazily continued into the
blockquote paragraph, then re-lexed into a nested empty list.
Give the blockquote its own paragraph variant whose list-interrupt
clause also matches a bare marker, so the list ends the blockquote and
becomes a sibling block. The top level paragraph rule is unchanged, so
an empty list still cannot interrupt a paragraph.
This commit is contained in:
+4
-2
@@ -177,8 +177,10 @@ const createParagraph = (listInterrupt: RegExp) => edit(_paragraph)
|
||||
|
||||
// only non-empty lists starting from 1 can interrupt paragraphs
|
||||
const paragraph = createParagraph(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/);
|
||||
// blockquotes can be interrupted by lists starting from any number
|
||||
const blockquoteParagraph = createParagraph(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/);
|
||||
// inside a blockquote a bare list marker (any number) starts a sibling list,
|
||||
// so it must not be lazily continued as paragraph text (unlike a top level
|
||||
// paragraph, where an empty list cannot interrupt)
|
||||
const blockquoteParagraph = createParagraph(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/);
|
||||
|
||||
const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/)
|
||||
.replace('paragraph', blockquoteParagraph)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<blockquote>
|
||||
<p>foo</p>
|
||||
</blockquote>
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<p>foo
|
||||
bar</p>
|
||||
</blockquote>
|
||||
<ol>
|
||||
<li></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,6 @@
|
||||
> foo
|
||||
-
|
||||
|
||||
> foo
|
||||
> bar
|
||||
1.
|
||||
Reference in New Issue
Block a user