Skip to content

Commit 2bf8f4d

Browse files
committed
fmt: automatically remove self-closing slash from void elements
Non-void elements will not be automatically fixed and the error will remain for the user to see. One reason for this behavior is to make sure we don't "sneakily" remove a self-closing tag from an element that was hiding a nesting error. By having the user face the problem they get a chance to discover the latent mistake and fix it, on top of learning a bit more about html. This is what I mean by latent nesting bug: ``` <body> <div /> <div> </body> ``` The indentation of this code seems to suggest that the two divs are sibling, while in reality the second one is a child of the first because in HTML self-closing slashes are ignored. As of today editors like VSCode will produce misleading indentation in the presence of a self-closing slash, helping perpetuate mistakes.
1 parent 936cd2f commit 2bf8f4d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/html/Ast.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ pub fn render(ast: Ast, src: []const u8, w: *Writer) !void {
13031303
}
13041304
}
13051305

1306-
if (current.self_closing) {
1306+
if (current.self_closing and !current.kind.isVoid()) {
13071307
try w.print("/", .{});
13081308
}
13091309
try w.print(">", .{});

0 commit comments

Comments
 (0)