Skip to content

Commit

Permalink
refactor(index): Collect attributes ourselves (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Aug 25, 2021
1 parent f145e88 commit 7869a0a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,23 @@ export class DomHandler {
if (this.elementCB) this.elementCB(elem);
}

public onopentag(name: string, attribs: { [key: string]: string }): void {
/** Attributes of the current element. */
private attribs: { [key: string]: string } = {};

public onopentagname(name: string): void {
this.attribs = {};
const type = this.options.xmlMode ? ElementType.Tag : undefined;
const element = new Element(name, attribs, undefined, type);
const element = new Element(name, this.attribs, undefined, type);
this.addNode(element);
this.tagStack.push(element);
}

public onattribute(name: string, value: string): void {
if (!Object.prototype.hasOwnProperty.call(this.attribs, name)) {
this.attribs[name] = value;
}
}

public ontext(data: string): void {
const { lastNode } = this;

Expand Down

0 comments on commit 7869a0a

Please sign in to comment.