Skip to content

Commit

Permalink
Do not loop in onEndTag as it does multiple calls itself
Browse files Browse the repository at this point in the history
My loop was skipping ahead and the subsequent calls to `onEndTag` were breaking the state.
  • Loading branch information
TomasHubelbauer committed Oct 13, 2024
1 parent d43c587 commit fdb87e3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,14 @@ export default class DOMParser {

element.onEndTag((tag) => {
// Handle an unclosed element being followed by a closing tag for another element
// Keep closing the element chain as void elements until we find the matching tag
while (document.activeElement?.parentElement && tag.name !== document.activeElement.tagName) {
if (document.activeElement?.parentElement && tag.name !== document.activeElement.tagName) {
// Mark as void only if there are no children, otherwise it is a
// case of an element with no closing tag closed by another
// element's opening tag via `autoClosingTags`
document.activeElement.isVoid = document.activeElement.children.length === 0;
document.activeElement = document.activeElement.parentElement;
}

document.activeElement = document.activeElement.parentElement;
document.activeElement = document.activeElement?.parentElement;
});
},
comments(comment) {
Expand Down

0 comments on commit fdb87e3

Please sign in to comment.