Skip to content

Fix spurious deeper nesting in a lazy blockquote continuation#4030

Open
spokodev wants to merge 1 commit into
markedjs:masterfrom
spokodev:fix/nested-blockquote-lazy-overnesting
Open

Fix spurious deeper nesting in a lazy blockquote continuation#4030
spokodev wants to merge 1 commit into
markedjs:masterfrom
spokodev:fix/nested-blockquote-lazy-overnesting

Conversation

@spokodev

Copy link
Copy Markdown
Contributor

Problem

In a nested blockquote, a paragraph line that lazily continues and is then
followed by a line restating the > markers is parsed into an extra, spurious
blockquote level (and a split paragraph) instead of continuing the same
paragraph.

Input:

> > a
b
> > c

marked (before this PR):

<blockquote>
<blockquote>
<p>a
b</p>
<blockquote>
<p>c</p>
</blockquote>
</blockquote>
</blockquote>

Expected — identical output from both commonmark 0.31.2 and
micromark + micromark-extension-gfm:

<blockquote>
<blockquote>
<p>a
b
c</p>
</blockquote>
</blockquote>

> > a\nb\n> > > c shows the same off-by-one-level (4 blockquotes in marked vs
the correct 3). Plain lazy nesting without a restated marker
(> > > foo\nbar, CommonMark example 250) is unaffected, which is why no
existing spec caught it.

Root cause

The nested-blockquote continuation branch re-lexes the inner blockquote from
oldToken.raw + '\n' + lines.join('\n'). oldToken.raw already had one >
marker stripped for the inner frame, but the appended continuation lines still
carry the outer markers, so a restated > > keeps one surplus > when recursed
and is read as a fresh deeper blockquote that interrupts the open paragraph. The
single-level path works only because the marker is stripped there via
blockquoteSetextReplace2; this branch bypassed that strip.

Fix

Strip one > marker from the continuation lines (same blockquoteSetextReplace2
the normal path uses) so they align with the inner frame, and rebuild raw from
the actual consumed source. Deeper markers (> > >) simply recurse one further
level, which is correct.

Test

Added test/specs/new/blockquote_nested_lazy_continuation (.md/.html).
Fails on master (2 failing spec cases), passes with the fix. Full suite green:
test:specs 1769 pass / 0 fail, test:unit 188 pass / 0 fail.

Reference: CommonMark 0.31.2 §6.3 (block quotes — laziness): a line beginning
with the blockquote's own markers followed by paragraph text continues that
paragraph, not a new deeper quote.

In a nested blockquote, a paragraph line that lazily continues and is
then followed by a line restating the `>` markers was parsed into an
extra, spurious blockquote level (and a split paragraph) instead of
continuing the same paragraph.

The continuation branch re-lexes the nested blockquote from
`oldToken.raw + '\n' + lines`, but `oldToken.raw` already had one `>`
marker stripped for the inner frame while the appended `lines` still
carry the outer markers, so a restated `> >` keeps one surplus `>` and is
read as a fresh deeper blockquote. Strip one marker from the continuation
lines (as the normal path does via `blockquoteSetextReplace2`) so they
align with the inner frame, and rebuild `raw` from the actual consumed
source. Both `commonmark` and `micromark` + GFM produce the merged,
non-over-nested output this now matches.
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

@spokodev is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marked-website Ready Ready Preview, Comment Jul 23, 2026 2:54pm

Request Review

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! 💯

@UziTech
UziTech requested review from calculuschild and styfle July 24, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants