-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Hi, first of all, thank you for this fantastic library.
I am using it to transform HTML attributes. During this transformation, it's possible for errors to occur. I'd like to display the source location of the attribute that caused the error. However I don't see any way to get the source location of an element or attribute.
I am using the element handlers like this:
const rewriter = new HTMLRewriter(callback);
rewriter.on('*[src]', {
async element(element) {
try {
element.setAttribute('src', await modify(element.getAttribute('src')));
} catch (err) {
// No way of getting the source location of the element or the "src" attribute
const lineNumber = ???;
const columnNumber = ???;
console.error(`A problem occurred on line ${lineNumber}, column ${columnNumber}`);
}
},
});
Could this feature be added?
Edit: A simple offset would also work, since I could use it to calculate the line and column numbers myself.
Metadata
Metadata
Assignees
Labels
No labels