diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-27 17:11:08 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-27 17:11:08 +0200 |
| commit | ef5c0341ca15f6862294802103b02992b29609e8 (patch) | |
| tree | 9b5a274a77d44053b8e53d249b2d59b754c9f673 /src/eval/html/Literal.zig | |
| parent | 9f1a0bf3b0437770a7b62fd28a8748908c38dac4 (diff) | |
style(html): split elements in multiple files
Diffstat (limited to 'src/eval/html/Literal.zig')
| -rw-r--r-- | src/eval/html/Literal.zig | 25 |
1 files changed, 25 insertions, 0 deletions
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); +} |
