Skip to content

fix: let indented and type 3-5 html blocks interrupt a paragraph - #4124

Merged
UziTech merged 2 commits into
markedjs:masterfrom
kevin9327:fix-html-interrupt-paragraph
Oct 9, 2026
Merged

UziTech merged 2 commits into
markedjs:masterfrom
kevin9327:fix-html-interrupt-paragraph

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Marked version: 18.0.14 (c18a64f)

Markdown flavor: CommonMark|GitHub Flavored Markdown

Description

CommonMark lets every HTML block type except 7 interrupt a paragraph, with up to three spaces of indentation like the other block starts. The html part of marked's paragraph interrupt only covers type 6 tags, <script|pre|style|textarea and <!--, and it has no indentation allowance, so two kinds of input end up as paragraph text instead of starting an HTML block.

Expectation

Some text
  <div>
*raw*
</div>
<p>Some text</p>
  <div>
*raw*
</div>

and likewise for <?php ... ?>, <!DOCTYPE html> and <![CDATA[ ... ]]> right after a paragraph line (types 3, 4 and 5). This is what commonmark.js produces.

Result

<p>Some text
  <div>
<em>raw</em>
</div></p>

The PI, declaration and CDATA lines are folded into the paragraph the same way.

What was attempted

Found while diffing marked (gfm: false) against commonmark.js on generated inputs.

The fix adds {0,3} and the type 3 to 5 start conditions to the html interrupt in the paragraph rules (CommonMark and GFM) and the GFM table rows, and adds the same start conditions to htmlBeginRegex, which the comment says mirrors the paragraph rule and is used to end list items. The html block rule itself already handles all of these once it gets a chance to run.

#4114 edits the same <(?:script|pre|style|textarea|!--) fragment for a different issue (whole tag names), so whichever lands second will need a small rebase.

Contributor

  • Test(s) exist to ensure functionality and minimize regression: test/specs/new/html_block_interrupts_paragraph fails before the change and passes after. Spec and unit tests pass locally.
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel

vercel Bot commented Oct 5, 2026

Copy link
Copy Markdown

@kevin9327 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 Oct 5, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
marked-website Ready Ready Preview Oct 9, 2026 3:02am UTC

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.

Thanks! 💯

@kevin9327

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

@styfle styfle 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.

Thanks!

@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.

Please fix the merge conflicts

@UziTech
UziTech merged commit eaa1fff into markedjs:master Oct 9, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
## [18.1.1](v18.1.0...v18.1.1) (2026-10-12)

### Bug Fixes

* **cli:** honor an explicitly empty string input ([#4113](#4113)) ([ec3a4e5](ec3a4e5))
* end blockquote before a lazy line after a heading, hr or html block ([#4115](#4115)) ([9e64a6a](9e64a6a))
* keep a backslash in a code span from hiding emphasis ([#4117](#4117)) ([6a57018](6a57018))
* keep a decoded character reference from forming a new one ([#4111](#4111)) ([6bbac0c](6bbac0c)), closes [#38](#38) [#112](#112)
* let indented and type 3-5 html blocks interrupt a paragraph ([#4124](#4124)) ([eaa1fff](eaa1fff))
* make walkTokens linear by appending values in place ([#4121](#4121)) ([627d9ae](627d9ae)), closes [#4120](#4120)
* match pre, script, style and textarea as whole tag names ([#4114](#4114)) ([0db74cb](0db74cb))
* preserve enclosing link state after parsing images ([#4123](#4123)) ([cc07bb9](cc07bb9))
* respect tab stops in list continuation indentation ([#4119](#4119)) ([4bd2528](4bd2528))

### Performance Improvements

* avoid repeated raw string copies in nested lists ([#4082](#4082)) ([7e8754d](7e8754d))

This branch was successfully deployed

1 active deployment
Preview — b774badb Deployed Oct 9, 2026 by vercel[bot]
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.

3 participants