Skip to content

Add missing tags to openImpliesClose for open <p> elements - #2493

Merged
fb55 merged 2 commits into
fb55:masterfrom
JiuYue0820:fix/p-implied-close-hgroup-menu-search
Oct 17, 2026
Merged

fb55 merged 2 commits into
fb55:masterfrom
JiuYue0820:fix/p-implied-close-hgroup-menu-search

Conversation

@JiuYue0820

@JiuYue0820 JiuYue0820 commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Per the WHATWG HTML parsing spec (https://html.spec.whatwg.org/multipage/syntax.html#optional-tags), the list of start tags whose start implies the end of an open <p> element includes center, dialog, dir, hgroup, menu, search and summary. These entries are missing from the openImpliesClose map in src/Parser.ts, so htmlparser2 nests these elements inside an open <p> instead of closing it, diverging from browser behavior. For example, parsing <p>text<menu>item</menu> keeps the <menu> inside the paragraph.

Fix

Add the seven missing entries to openImpliesClose:

  • center, dialog, dir, hgroup, menu, search, summary -> close open <p>

Verification

  • Added a regression test in src/Parser.spec.ts asserting that an open <p> is implicitly closed before <hgroup> opens.
  • vitest run: 7 test files, 188 tests passed (including the new regression test).
  • Existing fixtures/snapshots contain no occurrences of the affected tags, so no snapshots needed updating.

Co-authored-by: FirmamentalSpring 287222957+FirmaSpring@users.noreply.github.com

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Improved HTML parsing for additional elements that implicitly close open paragraphs.
    • Added support for correct paragraph handling around elements such as headings groups, menus, dialogs, and summaries.
  • Tests

    • Added coverage verifying that an open paragraph closes before an <hgroup> element begins.

Per the WHATWG HTML parsing spec, the list of start tags whose start
implies the end of an open <p> element includes center, dialog, dir,
hgroup, menu, search and summary. These entries were missing from the
openImpliesClose map, so htmlparser2 nested these elements inside an
open <p> instead of closing it, diverging from browser behavior.

Add the seven missing entries and a regression test asserting that an
open <p> is closed before <hgroup> opens.

All 188 tests pass (vitest run).

Co-authored-by: FirmamentalSpring <287222957+FirmaSpring@users.noreply.github.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3e27e075-0fb1-4ddf-8e96-76e05d0ec79b
📥 Commits

Reviewing files that changed from the base of the PR and between 6936c88 and 5a7e3c5.

📒 Files selected for processing: 2
  • src/Parser.spec.ts
  • src/Parser.ts
+-------------------------------------------------------------------------------------------------------------+
| Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. |
+-------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7a1018fb-7f09-4ae9-a1d8-9b733a2473df

📥 Commits

Reviewing files that changed from the base of the PR and between 34ec526 and 6936c88.

📒 Files selected for processing (2)
  • src/Parser.spec.ts
  • src/Parser.ts

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.

📝 Walkthrough

The parser now implicitly closes an open <p> before center, dialog, dir, hgroup, menu, search, and summary. A test verifies the close event precedes the <hgroup> opening event.

Changes: HTML implicit close handling

Layer / File(s) Summary
Paragraph close mappings and coverage
src/Parser.ts, src/Parser.spec.ts
The HTML tag map adds seven paragraph-closing elements. Tests verify automatic <p> closure before <hgroup> starts.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: vimzh

Merge Risk: ⚪ Minimal · up to 6936c

This localized parser change adds the missing implicit paragraph-closing behavior and includes regression coverage; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding missing tags to openImpliesClose so they close open

elements.

Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the tags in line,
“Close the paragraph; all is fine.”
&lt;hgroup&gt; starts with events in place,
Seven tags now share the case.
Hop, hop—clean parsing wins!

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the callback-order test has a non-blocking weakness.

Findings

  1. P2 Callback order goes unchecked ▶

Summary

Adds seven tags to openImpliesClose so they close an open paragraph in HTML mode.

  • Seven more HTML elements close an open paragraph before opening.

Reviews (2) · Last reviewed commit: "Merge branch 'master' into fix/p-implied..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@lbesecker195 lbesecker195 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked against the WHATWG tree-construction rules for the "in body" insertion mode: the start tags that close a p in button scope include center, dialog, dir, hgroup, menu, search, and summary, all of which were missing from openImpliesClose. Test added. LGTM.

@fb55
fb55 merged commit a4c60b8 into fb55:master Oct 17, 2026
10 of 11 checks passed
@fb55

fb55 commented Oct 17, 2026

Copy link
Copy Markdown
Owner

thanks!

Comment thread src/Parser.spec.ts
Comment on lines +228 to +234
const pClose = onclosetag.mock.calls.findIndex(
([name]) => name === "p",
);
const hgroupOpen = onopentag.mock.calls.findIndex(
([name]) => name === "hgroup",
);
expect(pClose).toBeLessThan(hgroupOpen);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Callback order goes unchecked

pClose and hgroupOpen are indexes in different spies, so comparing them does not check callback order. This test would still pass if onopentag("hgroup") ran before onclosetag("p", true), provided the paragraph closed first among close callbacks. Compare the spies’ mock.invocationCallOrder values or record both callbacks in one shared list.

Knowledge Base Used: Parser events and document state

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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