lib/zen/src/document/model.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 /// One source heading copied into caller-owned storage.
2 pub const Heading = struct {
3 /// Markdown heading depth from 1 through 6.
4 level: u8,
5 /// Visible heading text without an explicit anchor suffix.
6 text: []const u8,
7 /// Exact explicit ID or the generated collision-safe ID.
8 id: []const u8,
9 /// Byte offset of the heading marker in the Markdown source.
10 source_offset: usize,
11 };
12
13 /// Borrowed view of the headings held by active `Storage`.
14 pub const Document = struct {
15 headings: []const Heading = &.{},
16
17 /// Returns the first heading, or null when the document has none.
18 pub fn firstHeading(self: Document) ?Heading {
19 if (self.headings.len == 0) return null;
20 return self.headings[0];
21 }
22 };
23
24 /// Rejections produced before heading storage is acquired or changed.
25 pub const Exhaustion = error{
26 /// The document has more headings than storage admits.
27 HeadingCapacityExceeded,
28 /// Visible heading text needs more copied bytes than storage admits.
29 HeadingTextByteCapacityExceeded,
30 /// Resolved heading IDs need more copied bytes than storage admits.
31 HeadingIdByteCapacityExceeded,
32 /// A prior document still borrows this storage; reset after its last use.
33 DocumentStorageInUse,
34 };
35
36 /// Invalid explicit heading-anchor syntax.
37 pub const ParseError = error{
38 /// Two explicit anchors reserve the same case-sensitive page ID.
39 DuplicateHeadingAnchor,
40 /// An explicit anchor contains a byte outside its documented alphabet.
41 InvalidHeadingAnchor,
42 };
43
44 /// All heading inspection failures, including checked-capacity overflow.
45 pub const Error = Exhaustion || ParseError || error{CapacityOverflow};