Skip to content

Honor implied end tags for dt and dd - #319

Merged
taoqf merged 1 commit into
taoqf:mainfrom
adarshx01:fix/unclosed-dt-dd
Sep 7, 2026
Merged

Honor implied end tags for dt and dd#319
taoqf merged 1 commit into
taoqf:mainfrom
adarshx01:fix/unclosed-dt-dd

Conversation

@adarshx01

Copy link
Copy Markdown

Fixes #315

HTML lets dt/dd omit their end tags. The parser didn't close them when the next dt/dd started or when dl/body/html closed, so the stack didn't match and the leftover-tag cleanup dropped body/dl.

Same implied-end-tag tables already used for li/p/td.

Unclosed dt/dd left the parser stack mismatched, so closing a parent
dl/body dropped the surrounding tree. Close them the way HTML does:
another dt/dd starts, or the parent dl/body/html ends.

@taoqf taoqf left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

https://developer.mozilla.org/en-US/docs/Glossary/Void_element
According to this, dt&dd are not void elements.

@adarshx01

Copy link
Copy Markdown
Author

https://developer.mozilla.org/en-US/docs/Glossary/Void_element According to this, dt&dd are not void elements.

Thanks - agreed, dt and dd are not void elements, and this PR does not add them to voidTag.tags.

Void elements (br, img, …) cannot have children. dt/dd can; HTML only allows omitting the end tag:

https://html.spec.whatwg.org/multipage/syntax.html#optional-tags
https://html.spec.whatwg.org/multipage/grouping-content.html#the-dt-element

This repo already handles that for li/p/td via kElementsClosedByOpening / kElementsClosedByClosing. Same thing here so <dl><dt><dd></dl> does not leave dt/dd on the stack and get body/dl stripped (#315).

Happy to add a code comment on those entries making “optional end tag, not void” explicit if that helps.

@taoqf
taoqf merged commit f561cd0 into taoqf:main Sep 7, 2026
0 of 3 checks passed
@taoqf

taoqf commented Sep 7, 2026

Copy link
Copy Markdown
Owner

My mistake . Thank you. node-html-parser@9.0.4 released.

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.

[BUG] unclosed dd/dt tags corrupt the output

2 participants