Skip to content

Commit 4b2e1a1

Browse files
committed
html: fix svg and math detection
Previously we would still attempt to match html elements inside of svg and math contexts. Fixing this bug required adding extra logic to notice when, from inside those contexts, we detect a closing svg/math tag that would bring us back into an HTML context.
1 parent c8f0801 commit 4b2e1a1

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

src/html/Ast.zig

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -601,39 +601,40 @@ pub fn init(
601601
.after => nodes.items[current_idx].parent_idx,
602602
};
603603

604-
const e = elements.get(kind);
605-
const model = if (syntax_only or language != .html)
606-
undefined
607-
else
608-
try e.validateAttrs(
609-
gpa,
610-
language,
611-
&errors,
612-
&seen_attrs,
613-
&seen_ids_stack.items[seen_ids_stack.items.len - 1],
614-
nodes.items,
615-
parent_idx,
616-
src,
617-
tag.span,
618-
@intCast(nodes.items.len),
619-
);
620-
621-
if (kind == .template) {
622-
try seen_ids_stack.append(gpa, .empty);
604+
const e = elements.get(kind);
605+
const model = if (syntax_only or language != .html)
606+
undefined
607+
else
608+
try e.validateAttrs(
609+
gpa,
610+
language,
611+
&errors,
612+
&seen_attrs,
613+
&seen_ids_stack.items[seen_ids_stack.items.len - 1],
614+
nodes.items,
615+
parent_idx,
616+
src,
617+
tag.span,
618+
@intCast(nodes.items.len),
619+
);
620+
621+
if (kind == .template) {
622+
try seen_ids_stack.append(gpa, .empty);
623+
}
624+
625+
break :node .{
626+
.open = tag.span,
627+
.kind = kind,
628+
.model = model,
629+
.self_closing = self_closing,
630+
};
631+
} else if (std.mem.indexOfScalar(u8, name, '-') == null and !syntax_only) {
632+
try errors.append(gpa, .{
633+
.tag = .invalid_html_tag_name,
634+
.main_location = tag.name,
635+
.node_idx = @intCast(nodes.items.len),
636+
});
623637
}
624-
625-
break :node .{
626-
.open = tag.span,
627-
.kind = kind,
628-
.model = model,
629-
.self_closing = self_closing,
630-
};
631-
} else if (std.mem.indexOfScalar(u8, name, '-') == null and !syntax_only) {
632-
try errors.append(gpa, .{
633-
.tag = .invalid_html_tag_name,
634-
.main_location = tag.name,
635-
.node_idx = @intCast(nodes.items.len),
636-
});
637638
}
638639

639640
break :node .{
@@ -752,7 +753,11 @@ pub fn init(
752753
}
753754

754755
const name = tag.name.slice(src);
755-
const end_kind = switch (language) {
756+
const end_kind = if (svg_lvl == 1 and std.ascii.eqlIgnoreCase(name, "svg"))
757+
.svg
758+
else if (math_lvl == 1 and std.ascii.eqlIgnoreCase(name, "math"))
759+
.math
760+
else if (svg_lvl != 0 or math_lvl != 0) .___ else switch (language) {
756761
.superhtml => if (std.ascii.eqlIgnoreCase("ctx", name))
757762
.ctx
758763
else if (std.ascii.eqlIgnoreCase("super", name))

0 commit comments

Comments
 (0)