diff --git a/src/Parser.spec.ts b/src/Parser.spec.ts index b420b005e..17727b2c6 100644 --- a/src/Parser.spec.ts +++ b/src/Parser.spec.ts @@ -145,6 +145,15 @@ describe("API", () => { expect(p.endIndex).toBe(12); }); + test("should have the correct position for implied opening tags", () => { + const p = new Parser(); + + p.write("

"); + + expect(p.startIndex).toBe(0); + expect(p.endIndex).toBe(3); + }); + test("should parse <__proto__> (#387)", () => { const p = new Parser(null); diff --git a/src/Parser.ts b/src/Parser.ts index aae4cc17e..fa80bc268 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -246,6 +246,11 @@ export class Parser { if (this.lowerCaseTagNames) { name = name.toLowerCase(); } + + this.emitOpenTag(name); + } + + private emitOpenTag(name: string) { this.tagname = name; const impliesClose = @@ -307,11 +312,11 @@ export class Parser { } } else this.stack.length = pos; } else if (name === "p" && !this.options.xmlMode) { - this.onopentagname(name); + this.emitOpenTag(name); this.closeCurrentTag(); } } else if (!this.options.xmlMode && (name === "br" || name === "p")) { - this.onopentagname(name); + this.emitOpenTag(name); this.closeCurrentTag(); } }