aboutsummaryrefslogtreecommitdiff
path: root/src/title.zig
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-18 19:25:54 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-18 19:25:54 +0200
commit9b47b7ee8b80bf427116b4d2cf42e6f3c9d8be62 (patch)
tree70e12c0a4bb869957d2e06ef482bb856c5a0d4f4 /src/title.zig
parentfec006aaa5ee3683457ebfc2ba1755b077e14c79 (diff)
feat(ast): parse title
Diffstat (limited to 'src/title.zig')
-rw-r--r--src/title.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/title.zig b/src/title.zig
new file mode 100644
index 0000000..88848e5
--- /dev/null
+++ b/src/title.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const Lexed = @import("lexer/Lexed.zig");
+const Lexer = @import("lexer/Lexer.zig");
+const Element = @import("dom/Element.zig");
+const paragraph = @import("paragraph.zig");
+
+pub const Error = paragraph.Error || Lexer.Error;
+
+pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
+ const v = (try l.next(alloc)).?;
+ var el = try Element.init(alloc, .content, switch (v.content.items.len) {
+ 1 => "h1",
+ 2 => "h2",
+ 3 => "h3",
+ 4 => "h4",
+ 5 => "h5",
+ 6 => "h6",
+ else => unreachable,
+ });
+ try el.appendContent(try paragraph.parseContent(alloc, l));
+ return el;
+}