Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ describe("API", () => {
p.write("<__proto__>");
});

it("should implicitly close <td> when <th> opens", () => {
const onclosetag = vi.fn();
const onopentagname = vi.fn();

new Parser({ onclosetag, onopentagname }).end(
"<table><tr><td>A<th>B</tr></table>",
);

// <th> must auto-close <td>, making them siblings per the HTML spec
expect(onclosetag).toHaveBeenCalledWith("td", true);
const tdClose = onclosetag.mock.calls.findIndex(
([name]: [string]) => name === "td",
);
const thOpen = onopentagname.mock.calls.findIndex(
([name]: [string]) => name === "th",
);
expect(tdClose).toBeLessThan(thOpen);
});

it("should support custom tokenizer", () => {
class CustomTokenizer extends Tokenizer {}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const rtpTags = new Set(["rt", "rp"]);

const openImpliesClose = new Map<string, Set<string>>([
["tr", new Set(["tr", "th", "td"])],
["th", new Set(["th"])],
["th", new Set(["th", "td"])],
["td", new Set(["thead", "th", "td"])],
["body", new Set(["head", "link", "script"])],
["a", new Set(["a"])],
Expand Down
Loading