diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-08 13:52:25 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-08 13:52:25 +0200 |
| commit | ec30b659dfd337f5edf512ea78032fe18251b704 (patch) | |
| tree | 8fe9cfd4b965c7ffbac7f190681b6ac5ac9f8ae7 /src/z/html/element.zig | |
| parent | 0a2f6f8cc48258fca60df2f193790b2d94a9d0f6 (diff) | |
refactor html module
Diffstat (limited to 'src/z/html/element.zig')
| -rw-r--r-- | src/z/html/element.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/z/html/element.zig b/src/z/html/element.zig new file mode 100644 index 0000000..739eb0b --- /dev/null +++ b/src/z/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), + }; + } +}; |