aboutsummaryrefslogtreecommitdiff
path: root/src/eval/html/Literal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval/html/Literal.zig')
-rw-r--r--src/eval/html/Literal.zig25
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);
+}