aboutsummaryrefslogtreecommitdiff
path: root/src/quote.zig
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/quote.zig
parent7b1b855ed68b4fc72d01de170226ea0fcc74a512 (diff)
feat(): support quote
Diffstat (limited to 'src/quote.zig')
-rw-r--r--src/quote.zig58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/quote.zig b/src/quote.zig
new file mode 100644
index 0000000..8c24c7e
--- /dev/null
+++ b/src/quote.zig
@@ -0,0 +1,58 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const Token = @import("lexer/Token.zig");
+const Lexer = @import("lexer/Lexer.zig");
+const Element = @import("eval/Element.zig");
+const paragraph = @import("paragraph.zig");
+const testing = @import("testing.zig");
+const doTest = testing.do;
+const doTestError = testing.doError;
+
+pub const Error = paragraph.Error || Allocator.Error;
+
+pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
+ const root = try Element.Root.init(alloc);
+ while (l.peek()) |next| switch (next.kind) {
+ .quote => {
+ l.consume();
+ continue;
+ },
+ .weak_delimiter => {
+ l.consume();
+ if (l.peek()) |it| if (it.kind != .quote) break;
+ root.append((try Element.Literal.init(alloc, " ")).element());
+ continue;
+ },
+ .strong_delimiter => break,
+ else => root.append(try paragraph.parseLine(alloc, l)),
+ };
+ const el = try Element.Quote.init(alloc, root.element());
+ const v = l.peek() orelse return el.element();
+ if (v.kind == .strong_delimiter) {
+ l.consume();
+ return el.element();
+ }
+ const attr = try paragraph.parse(alloc, l);
+ const p_el: *Element.paragraph.Block = @ptrCast(@alignCast(attr.ptr));
+ el.attribution = (try p_el.toRoot(alloc)).element();
+ return el.element();
+}
+
+test {
+ const alloc = std.testing.allocator;
+
+ try doTest(parse, alloc, "> hello world", "<figure><blockquote>hello world</blockquote></figure>");
+ try doTest(parse, alloc, ">hello world", "<figure><blockquote>hello world</blockquote></figure>");
+ try doTest(parse, alloc, "> hello world", "<figure><blockquote>hello world</blockquote></figure>");
+
+ try doTest(parse, alloc,
+ \\> hello
+ \\>world
+ , "<figure><blockquote>hello world</blockquote></figure>");
+ try doTest(parse, alloc,
+ \\> hello
+ \\>world
+ \\attribution sur
+ \\plusieurs lignes
+ , "<figure><blockquote>hello world</blockquote><figcaption>attribution sur plusieurs lignes</figcaption></figure>");
+}