blob: 739eb0b5097be65998d5dd762b1b40ea6c3770f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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),
};
}
};
|