Skip to content

Commit 624a3ee

Browse files
committed
fix rendering of scripted self-closing xml elements
1 parent d4d81e1 commit 624a3ee

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/template.zig

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const assert = std.debug.assert;
23
const Writer = std.Io.Writer;
34
const scripty = @import("scripty");
45
const tracy = @import("tracy");
@@ -907,11 +908,19 @@ pub fn SuperTemplate(comptime ScriptyVM: type) type {
907908
}
908909

909910
if (elem.kind.isElement() and !elem.kind.isVoid()) {
910-
// Print up to the close tag
911-
const end = elem.close.end;
912-
const up_to_attr = tpl.src[tpl.print_cursor..end];
913-
writer.writeAll(up_to_attr) catch return error.OutIO;
914-
tpl.print_cursor = end;
911+
if (elem.self_closing) {
912+
assert(tpl.html.language == .xml);
913+
// Synthesize a closing tag
914+
writer.print("</{s}>", .{
915+
elem.open.getName(tpl.src, tpl.html.language).slice(tpl.src),
916+
}) catch return error.OutIO;
917+
} else {
918+
// Print up to the close tag
919+
const end = elem.close.end;
920+
const up_to_end = tpl.src[tpl.print_cursor..end];
921+
writer.writeAll(up_to_end) catch return error.OutIO;
922+
tpl.print_cursor = end;
923+
}
915924
}
916925
_ = tpl.cursor.next();
917926
},

0 commit comments

Comments
 (0)