BUG: onopentag and onclosetag has a few issues with Tag button

This issue has been tracked since 2021-07-26.

I found a issues when my dom tree include a button。

version: 4.1.0

const htmlparser2 = require("htmlparser2");
const parser = new htmlparser2.Parser({
    onopentag(name, attributes) {
       console.log('opentag', name)
    },
    onclosetag(tagname) {
        console.log('closeTag', tagname)
    },
});
parser.write(
    "<button><input /></button>"
);
parser.end();

Output:

"opentag button"
"closeTag button"
"opentag input"
"closeTag input"

Expect:

"opentag button"
"opentag input"
"closeTag input"
"closeTag button"

This issues only happen with a button tag contain other tag.

fb55 wrote this answer on 2021-07-26

button elements are void elements in HTML and don't need a closing tag. If you want to skip most transforms imposed by the HTML spec, have a look at the xmlMode option.

More Details About Repo
Owner Name fb55
Repo Name htmlparser2
Full Name fb55/htmlparser2
Language TypeScript
Created Date 2011-08-27
Updated Date 2023-03-19
Star Count 3793
Watcher Count 50
Fork Count 370
Issue Count 4

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date