-
-
Notifications
You must be signed in to change notification settings - Fork 396
Closed
Labels
Description
When using Tokenizer's onattribend callback it's endIndex may indicate different position, depending on the structure of the attribute.
Worst case scenario is NoValue attribute, then endIndex is not related to the attribute at all.
Code to reproduce:
const { Tokenizer } = require("htmlparser2");
function parse(html) {
console.log('\n' + html);
const tokenizer = new Tokenizer({}, {
onopentagname() {},
onopentagend() {},
onattribname() {},
onattribdata() {},
onattribend(quote, endIndex) {
console.log(' '.repeat(endIndex) + '^');
console.log('Attribute endIndex:', endIndex);
},
onend() {},
onattribentity() {},
oncdata() {},
onclosetag() {},
oncomment() {},
ondeclaration() {},
onprocessinginstruction() {},
onselfclosingtag() {},
ontext() {},
ontextentity() {},
});
tokenizer.write(html);
tokenizer.end();
}
parse('<a aaaaa >');
parse('<a aaaaa >');
parse('<a a=aaa >');
parse('<a a="a" >');Output:
<a aaaaa >
^
Attribute endIndex: 11
<a aaaaa >
^
Attribute endIndex: 9
<a a=aaa >
^
Attribute endIndex: 8
<a a="a" >
^
Attribute endIndex: 7
Ideally I would expect one value for all cases above (probably 7).
Reactions are currently unavailable