aboutsummaryrefslogtreecommitdiff
path: root/src/eval/Title.zig
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-25 17:18:00 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-25 17:18:00 +0200
commitc008d747534f4c8aa59b045efbca754618e14b41 (patch)
tree68c094fed420230985724c300195c0389d2339e8 /src/eval/Title.zig
parenta3e7c462dadadc6986d93f6f0203ca7a02863ef8 (diff)
style(eval): move in its own package
Diffstat (limited to 'src/eval/Title.zig')
-rw-r--r--src/eval/Title.zig45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/eval/Title.zig b/src/eval/Title.zig
new file mode 100644
index 0000000..56524ad
--- /dev/null
+++ b/src/eval/Title.zig
@@ -0,0 +1,45 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const HTML = Parent.HTML;
+const Parent = @import("Element.zig");
+
+level: u3,
+content: Parent,
+
+const Self = @This();
+
+pub fn init(alloc: Allocator, level: u3, content: Parent) !*Self {
+ const v = try alloc.create(Self);
+ v.* = .{ .level = level, .content = content };
+ return v;
+}
+
+pub fn element(self: *Self) Parent {
+ return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = html } };
+}
+
+pub fn deinit(self: *Self, alloc: Allocator) void {
+ self.element().deinit(alloc);
+}
+
+fn destroy(context: *anyopaque, alloc: Allocator) void {
+ var self: *Self = @ptrCast(@alignCast(context));
+ self.content.deinit(alloc);
+ alloc.destroy(self);
+}
+
+fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML {
+ const self: *Self = @ptrCast(@alignCast(context));
+ var el = try HTML.init(alloc, .content, switch (self.level) {
+ 1 => "h1",
+ 2 => "h2",
+ 3 => "h3",
+ 4 => "h4",
+ 5 => "h5",
+ 6 => "h6",
+ else => unreachable,
+ });
+ errdefer el.deinit();
+ try el.appendContent(try self.content.html(alloc));
+ return el;
+}