Skip to content

Conversation

@ig3
Copy link

@ig3 ig3 commented Jan 7, 2026

This change is a more proper fix for #294.

With this change, unclosed p elements are closed at the end of their parent element according to the
spec:

if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.

With the exception that there is no provision for avoiding closing a p element if the parent element is an autonomous custom element. However, it is not obvious that node-html-parser supports autonomous custom elements, so the exclusion may not be significant. If the parent element is an autonomous custom element, then an unclosed p element will be closed incorrectly.

test valid.js was modified. In fact 'hillcrestpartyrentals.html' is valid HTML and the test incorrectly required that valid() return false for this HTML sample. With the recent changes, valid() correctly returns true and the test has been modified accordingly.

All tests are passing, including a new test specific to #294.

ig3 added 4 commits January 7, 2026 16:41
…seable

With this change, the valid HTML

> `<body><main class=h-entry><p>hello</main></body>`

is parsed correctly.

Furthermore, p element close tags may be omitted according to the
[spec](https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element) if:

> there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.

With this change, all these cases are handled correctly With the
exception that there is no exclusion of autonomous custom elements so
that p elements will be closed incorrectly when they are contained in
such. However, it is not immediately obvious that node-html-parser
supports autonomous custom elements, so this omission may not be
significant.
Within valid.js, the test 'hillcrestpartyrentals.html  should return
Object with valid: false.  not closing <p> tag on line 476' was
implemented incorrectly. In fact the HTML is valid. All the p elements
without close tags are contained in td elements and, therefore, the
closing tag is not required. The return should be true.
Test for taoqf#227 was broken by previous commit. This fixes it. All tests
are now passing.
@taoqf taoqf merged commit 5625286 into taoqf:main Jan 7, 2026
0 of 4 checks passed
@taoqf
Copy link
Owner

taoqf commented Jan 7, 2026

Thank you.

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