aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-28 20:52:56 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-28 20:52:56 +0200
commitc6e771fff0515d3a8e0cbc928c103b6c86f22c0f (patch)
tree6b3130e33680d5beb1e6ab9bba818352e83657dc /src/eval
parent7b1b855ed68b4fc72d01de170226ea0fcc74a512 (diff)
feat(): support quote
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/Element.zig1
-rw-r--r--src/eval/blocks.zig41
2 files changed, 42 insertions, 0 deletions
diff --git a/src/eval/Element.zig b/src/eval/Element.zig
index 4600abf..73dfb94 100644
--- a/src/eval/Element.zig
+++ b/src/eval/Element.zig
@@ -10,6 +10,7 @@ const blocks = @import("blocks.zig");
pub const Code = blocks.Code;
pub const Figure = blocks.Figure;
pub const Callout = blocks.Callout;
+pub const Quote = blocks.Quote;
pub const Node = struct {
ptr: *anyopaque,
diff --git a/src/eval/blocks.zig b/src/eval/blocks.zig
index cbb95b1..32f2de3 100644
--- a/src/eval/blocks.zig
+++ b/src/eval/blocks.zig
@@ -138,3 +138,44 @@ pub const Callout = struct {
return el.element();
}
};
+
+pub const Quote = struct {
+ content: Element,
+ attribution: ?Element = null,
+ node: Node = .{
+ .ptr = undefined,
+ .vtable = .{ .element = fromNode },
+ },
+
+ const Self = @This();
+
+ pub fn init(alloc: Allocator, content: Element) !*Self {
+ const v = try alloc.create(Self);
+ v.* = .{ .content = content };
+ v.node.ptr = v;
+ return v;
+ }
+
+ pub fn element(self: *Self) Element {
+ return .{ .ptr = self, .vtable = .{ .html = html, .node = getNode } };
+ }
+
+ fn getNode(context: *anyopaque) *Node {
+ const self: *Self = @ptrCast(@alignCast(context));
+ return &self.node;
+ }
+
+ fn fromNode(context: *anyopaque) Element {
+ const self: *Self = @ptrCast(@alignCast(context));
+ return self.element();
+ }
+
+ fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML {
+ const self: *Self = @ptrCast(@alignCast(context));
+ const quote = try Element.Simple("blockquote").init(alloc);
+ quote.content = self.content;
+ var el = try Figure.init(alloc, quote.element());
+ el.caption = self.attribution;
+ return try el.element().html(alloc);
+ }
+};