From c6e771fff0515d3a8e0cbc928c103b6c86f22c0f Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 28 Apr 2026 20:52:56 +0200 Subject: feat(): support quote --- src/eval/Element.zig | 1 + src/eval/blocks.zig | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'src/eval') 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); + } +}; -- cgit v1.2.3