aboutsummaryrefslogtreecommitdiff
path: root/src/title.zig
blob: d9b5612234384a9d44db7cbb93b884eb0bf3fad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 = error{InvalidTitleContent} || paragraph.Error || Lexer.Error;

pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
    var 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));
    v = (try l.next(alloc)) orelse return el;
    if (!v.kind.isDelimiter()) return Error.InvalidTitleContent;
    v.deinit();
    return el;
}