From 0b2af471b6d5dfc4eaf53639102c1b854bbb324b Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 12 Oct 2026 09:43:19 +0200 Subject: first version of zilch --- src/zilch/html/element.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/zilch/html/element.zig (limited to 'src/zilch/html/element.zig') diff --git a/src/zilch/html/element.zig b/src/zilch/html/element.zig new file mode 100644 index 0000000..739eb0b --- /dev/null +++ b/src/zilch/html/element.zig @@ -0,0 +1,30 @@ +const std = @import("std"); +const mod = @import("root.zig"); +const Attribute = mod.Attribute; +const Tag = mod.Tag; + +pub const Element = union(enum) { + const Self = @This(); + + tag: Tag, + string: []const u8, + + pub fn node(name: []const u8, attributes: anytype, children: []const Element) Self { + return .{ .tag = .tag(name, attributes, children) }; + } + + pub fn @"void"(name: []const u8, attribute: anytype) Self { + return .{ .tag = .void(name, attribute) }; + } + + pub fn text(content: []const u8) Self { + return .{ .string = content }; + } + + pub fn format(self: *const Self, writer: *std.Io.Writer) !void { + try switch (self.*) { + .string => |content| writer.writeAll(content), + .tag => |n| n.format(writer), + }; + } +}; -- cgit v1.2.3-70-g09d2