From ef5c0341ca15f6862294802103b02992b29609e8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 27 Apr 2026 17:11:08 +0200 Subject: style(html): split elements in multiple files --- src/eval/html/Literal.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/eval/html/Literal.zig (limited to 'src/eval/html/Literal.zig') diff --git a/src/eval/html/Literal.zig b/src/eval/html/Literal.zig new file mode 100644 index 0000000..d3b697f --- /dev/null +++ b/src/eval/html/Literal.zig @@ -0,0 +1,25 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const List = std.ArrayList; +const html = @import("html.zig"); +const Element = @import("Element.zig"); +const Error = Element.Error; + +literal: []const u8, + +const Self = @This(); + +pub fn init(alloc: Allocator, literal: []const u8) Error!*Element.Literal { + const v = try alloc.create(Self); + v.* = .{ .literal = try html.escape(alloc, literal) }; + return v; +} + +pub fn element(self: *Self) Element { + return .{ .vtable = .{ .render = Self.render }, .ptr = self }; +} + +fn render(context: *anyopaque, alloc: Allocator) Error![]const u8 { + const self: *Self = @ptrCast(@alignCast(context)); + return try alloc.dupe(u8, self.literal); +} -- cgit v1.2.3