Skip to content
Open
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
26 changes: 26 additions & 0 deletions src/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,32 @@ describe("API", () => {
expect(tbodyClose).toBeLessThan(theadOpen);
});

it("should keep a <button> inside <select> open (customizable select)", () => {
expect(
tagEvents(
"<select><button><selectedcontent></selectedcontent></button><option>A</option></select>",
),
).toEqual([
"<select>",
"<button>",
"<selectedcontent>",
"</selectedcontent>",
"</button>",
"<option>",
"</option>",
"</select>",
]);
});

it("should still close an open <button> when another <button> starts", () => {
expect(tagEvents("<button>A<button>B")).toEqual([
"<button>",
"</button>",
"<button>",
"</button>",
]);
});

it("should implicitly close <td> when <th> opens", () => {
const onclosetag = vi.fn();
const onopentagname = vi.fn();
Expand Down
4 changes: 3 additions & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const formTags = new Set([
"datalist",
"textarea",
]);
// A customizable `<select>` may start with a `<button>`, so it is the one form tag a button leaves open.
const buttonTags = new Set([...formTags].filter((tag) => tag !== "select"));
const pTag = new Set(["p"]);
const headingTags = new Set(["h1", "h2", "h3", "h4", "h5", "h6", "p"]);
const tableSectionTags = new Set(["thead", "tbody", "tfoot", "tr", "td", "th"]);
Expand All @@ -34,7 +36,7 @@ const openImpliesClose = new Map<string, Set<string>>([
["select", formTags],
["input", formTags],
["output", formTags],
["button", formTags],
["button", buttonTags],
["datalist", formTags],
["textarea", formTags],
["option", new Set(["option"])],
Expand Down