fix: keep trailing text on HTML block close line for PI, declarations, and CDATA#3991
Open
sarathfrancis90 wants to merge 1 commit into
Open
fix: keep trailing text on HTML block close line for PI, declarations, and CDATA#3991sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
…, and CDATA CommonMark ends HTML blocks of types 3 (<?...?>), 4 (<!...>), and 5 (<![CDATA[...]]>) on the line that contains the closing delimiter, and the whole of that line - including any text after the delimiter - is part of the block (see spec example 177 for the type 2 comment equivalent). marked already does this for comments via the trailing [^\n]* in rule 2, but rules 3-5 stopped at the closing delimiter, so trailing text on the same line was split off and reparsed as a paragraph. For example '<?php ?>*x*' rendered the '*x*' as emphasis instead of leaving it inside the raw HTML block. Match the comment rule by consuming the rest of the closing line before the newline. Added a new spec test covering all three block types.
|
@sarathfrancis90 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.
|
UziTech
approved these changes
Jun 16, 2026
UziTech
left a comment
Member
There was a problem hiding this comment.
Nice catch! Thanks for fixing this 💯
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.
Description
While checking marked against the CommonMark spec I noticed that text following the closing delimiter of an HTML block on the same line is dropped from the block for type 3 (
<?...?>), type 4 (<!...>), and type 5 (<![CDATA[...]]>).CommonMark ends these blocks on the line containing the closing delimiter, and the entire line — including anything after the delimiter — is part of the raw HTML block. marked already handles this for type 2 comments (spec example 177 shows
<!-- foo -->*bar*keeping*bar*as raw text), but rules 3–5 stopped right at the delimiter, so the trailing text got split off and reparsed.For example:
rendered as:
instead of leaving
*not emphasis*inside the HTML block like the reference does.Fix
The comment rule (2) already consumes the rest of the closing line with a trailing
[^\n]*. I applied the same to rules 3, 4, and 5 so they consume to the end of the closing line before the newline.Tests
Added
test/specs/new/html_block_trailing_text.mdcovering all three block types. It fails onmasterand passes with this change. Full CommonMark/GFM spec suites, unit tests, lint, types, and the ReDoS check are all green, and the CommonMark conformance score is unchanged.Contributor checklist
npm test)npm run lint)