Add missing tags to openImpliesClose for open <p> elements
Merged
JI
1mo ago+25+25+01234567890123456789-0-0-0123456789
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.tsasserting 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
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.
- Added coverage verifying that an open paragraph closes before an