Fix: #294 Closing tag is missing but valid HTML is still not parseable#297
Merged
taoqf merged 4 commits intotaoqf:mainfrom Jan 7, 2026
Merged
Fix: #294 Closing tag is missing but valid HTML is still not parseable#297taoqf merged 4 commits intotaoqf:mainfrom
taoqf merged 4 commits intotaoqf:mainfrom
Conversation
…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.
Owner
|
Thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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.