Skip to content

Invalid HTML element nesting is corrected, but only for some elements? #295

@Hurtak

Description

@Hurtak

It seems that the node-html-parser is doing some kind of correction of elements that have invalid HTML nesting, but only in some cases?

// valid HTML - nesting kept
const parsedA = parse(`<div>foo<div>bar</div></div>`);
console.log(parsedA.outerHTML); // `<div>foo<div>bar</div></div>`

// invalid HTML (p nested inside of p) - nesting changed
const parsedB = parse(`<p>foo<p>bar</p></p>`);
console.log(parsedB.outerHTML); // `<p>foo</p><p>bar</p>`

// invalid HTML (ul nested inside of p) - nesting kept
const parsedB = parse(`<p>foo<ul><li>bar</li></ul></p>`);
console.log(parsedB.outerHTML); // `<p>foo<ul><li>bar</li></ul></p>`

I found this issues #211 from @lehtu that says there is invalid nesting correction, but it only says it fixes the a tag, but the code above suggests that it is also happening for other elements like p? Shouldn't this be consistent - meaning either fix all invalid nesting or do not fix any invalid nesting?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions