Skip to content

fix: honor HTML block interruption tag names - #4239

Open
hakarrr wants to merge 15 commits into
markedjs:masterfrom
hakarrr:fix/html-interruption-tag-names
Open

hakarrr wants to merge 15 commits into
markedjs:masterfrom
hakarrr:fix/html-interruption-tag-names

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Marked version: master, c6b22e8

Markdown flavor: CommonMark / GitHub Flavored Markdown

Description

The shared HTML interruption lookahead matches tag names only in lowercase. For example:

a
<DIV>
===

Expectation

The uppercase block tag interrupts the paragraph, just as <div> does. The remaining lines stay raw HTML, not a heading. HTML block start conditions 1 and 6 match tag names without case sensitivity.

CommonMark demo

Result

Marked currently makes the paragraph and uppercase tag into a setext heading. Uppercase block tags can also fail to end a paragraph, a lazy blockquote paragraph, or a GFM table.

Marked master demo

What was attempted

Expand only ASCII letters in the interruption lookahead's tag names into explicit case pairs. Keep the <![CDATA[ marker case-sensitive. Also exclude meta from this interruption lookahead: it is a type-7 tag, not one of the type-6 block tag names. Arbitrary inline tags still cannot interrupt a paragraph. Build the legacy lookaheads separately for pedantic mode so its grammar stays unchanged.

The fixtures cover mixed-case block tags, raw-text tags, closing tags, tag-name boundaries, inline-tag and meta controls, CDATA controls, GFM tables, and retained pedantic behavior.

Validation on the final patch:

  • npm test: 2,043 spec tests and 256 unit tests passed, plus UMD, CJS, type, and lint checks.
  • npm run build:reset
  • git diff --check

Contributor

  • Tests exist to ensure functionality and minimize regression.
  • No tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places. (Not a new feature.)

Committer

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

hakarrr and others added 11 commits November 17, 2026 13:30
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

@hakarrr 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 Nov 17, 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 Dec 5, 2026 4:18am UTC

Request Review

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Merged master into this branch (7da52e9) to resolve a conflict in src/rules.ts: master rewrote blockquote (first line vs later lines), so I kept that structure and made it a createBlockquote(paragraph) factory; normal and GFM use it with blockquoteParagraph, and pedantic uses it with the pedantic HTML-interrupt paragraph this PR adds. npm test passes locally on the merged tree (specs, unit, types, lint). GitHub's web conflict editor does not allow a commit message, so this merge commit has no Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> trailer. The original commits keep it. If you squash, please keep that trailer in the squash message.

@@ -0,0 +1,80 @@
---
gfm: false

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.

If this doesn't change between GFM and CommonMark we don't need to test both. Ideally we should have the least amount of tests that verify that the fix is working.

hakarrr and others added 2 commits November 28, 2026 17:20
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. I removed the duplicate html_interrupt_case fixture pair in 8a4baa5 and af8aa23.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

@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 for working on this! A few issues need to be addressed before this can be merged:

  1. Benchmark & recheck regression (src/rules.ts):
    Expanding every ASCII letter in _tag and specialTag into [aA] character classes via caseInsensitiveTag inflates the hot-path block regexes (paragraph, blockGfm.paragraph, lheading, lheadingGfm, gfmTable, and blockquote), causing:

    • A consistent +4–5 percentage-point regression in npm run bench vs master (median across 3 interleaved runs: master 4906 ms / 27% slower than commonmark vs PR 5043 ms / 32% slower than commonmark).
    • node test/recheck.ts regressing from safe on master to timeout on block.normal.blockquote and block.normal.lheading.

    Since every other sub-pattern in paragraph, lheading, blockquote, and gfmTable is case-invariant (and block.normal.html already compiles with 'i'), please consider using the /i flag (or another approach that avoids [aA] expansion) so npm run bench matches master and recheck remains safe.

  2. GFM-noncompliant test assertions (test/specs/new/table_html_interrupt_case.{md,html}):
    Standalone <SPAN> and <META> are Type-7 HTML blocks and do terminate tables in GitHub GFM (cmark-gfm), so asserting they remain inside <tbody> locks in non-GFM behavior. Please update those negative-control rows to non-Type-7 inline HTML (e.g., <SPAN> x and <META> x) or remove them.

  3. Inconsistent meta handling & pedantic duplication (src/rules.ts):

    • Stripping |meta only inside createHtmlInterrupt(true) leaves meta in _tag, block.normal.html, and other.htmlBeginRegex (which mirrors paragraph interruption for lists). Removing meta directly from _tag (if all spec tests pass) would keep paragraph, list, and HTML block handling consistent.
    • Keeping separate _htmlInterruptPedantic, lheadingPedantic, and createBlockquote factories adds complexity and bundle size just to preserve accidental case-sensitivity in pedantic mode, even though Original Markdown.pl does not match Marked's legacy > a\n<SCRIPT> blockquote split. Also note that <SCRIPT> in html_interrupt_case_pedantic.md triggers HTTP 403 on the Daring Fireball Dingus WAF if the pedantic fixture is kept.

@hakarrr
hakarrr force-pushed the fix/html-interruption-tag-names branch from d9c1591 to 8aa9e29 Compare December 5, 2026 18:51

This branch was successfully deployed

1 active (outdated) deployment
Preview — d9c1591f Deployed Dec 5, 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.

2 participants