Repository navigation
fix: do not continue a block quote paragraph from a whitespace-only line - #4134
Open
OsamaAnsar wants to merge 1 commit into
Open
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
In `> a\n> \nb` the marker consumes one space and the remaining whitespace-only text matched the lazy paragraph branch of the blockquote rule, which then swallowed the following unquoted line into the quote. A line with only whitespace after the marker is blank and must end the paragraph, as for `>` and `> `.
|
@OsamaAnsar is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Marked version: 18.1.1 (master at cdbdc01)
Markdown flavor: CommonMark
Description
Expectation
Text after a block quote line that has two or more trailing spaces after the
>should end the quote, like it does for>and>. CommonMark, commonmark.js and markdown-it all give:Result
On master the unquoted line
bis swallowed into the block quote (marked.parse('> a\n> \nb')):With three trailing spaces (
'> a\n> \nb')bis also inside the quote and gets a hard line break:<blockquote>\n<p>a\n<br>b</p>\n</blockquote>\n. And'> \nb'(a quote whose only line is whitespace) gives<blockquote>\n<p>b</p>\n</blockquote>\ninstead of an empty quote followed by<p>b</p>.'> a\n>\nb'and'> a\n> \nb'already work.What was attempted
In the
blockquoterule,> ?consumes one space after the marker, and a whitespace-only remainder (>leaves a single space) then matches theparagraphalternative, which lazily continues onto the next unquoted line. The fix keeps whitespace-only lines out of that branch with a negative lookahead that guards only the paragraph alternative, so they fall through to the existing[^\n]*branch like>and>do:After the fix (same inputs):
'> a\n> \nb'-><blockquote>\n<p>a\n </p>\n</blockquote>\n<p>b</p>\n,'> a\n> \nb'-><blockquote>\n<p>a\n </p>\n</blockquote>\n<p>b</p>\n,'> \nb'-><blockquote>\n</blockquote>\n<p>b</p>\n. A stray whitespace-only line is still left inside the quote's paragraph (<p>a\n </p>); this PR does not try to remove it. The spec runner's HTML differ ignores that whitespace.How I checked it:
npm test(build:reset, build:docs, specs, unit, umd, cjs, types, lint): exit 0. Specs 1915/1915 and unit 199/199 with the fix; on unmodified master the specs are 1911 pass with my 2 new spec files failing (4 failing test entries: suite + case each), so no existing spec changed.src/rules.tschange, rebuilt, and confirmed the built bundle no longer had the lookahead and reproduced the master output above: both new specs fail. Restored the change, rebuilt: both pass.npm run test:redos: theblock.normal.blockquoteandblock.gfm.blockquoteregexes are reported safe with the change.Test files added under
test/specs/new/:blockquote_whitespace_only_line(two quotes with 2 and 3 trailing spaces followed by an unquoted line) andblockquote_whitespace_only_empty(>then an unquoted line).Nearby open PRs: #4110 (tab after the block quote marker) changes
Tokenizer.ts/rules.tsaround block quote markers but not this regex; I did not find an open PR that changes theblockquoterule.Contributor
Committer
In most cases, this should be a different person than the contributor.