pub struct NoteDocument { /* private fields */ }Expand description
A parsed nb note, todo, or bookmark.
NoteDocument owns the complete original source as
Vec<u8>. The source is byte-identical to the input passed
to [parse]. The kind-specific ownership partition is
exposed via accessor methods (e.g., NoteDocument::title,
NoteDocument::body, NoteDocument::url) and the
NoteDocument::tag_token_spans view.
See the P1 specification for the full contract.
Implementations§
Source§impl NoteDocument
impl NoteDocument
Sourcepub fn source(&self) -> &[u8] ⓘ
pub fn source(&self) -> &[u8] ⓘ
The original source bytes, byte-identical to the input
passed to [parse].
Sourcepub fn emit(&self) -> &[u8] ⓘ
pub fn emit(&self) -> &[u8] ⓘ
Returns a slice into the retained source bytes,
byte-identical to the original input. Equivalent to
NoteDocument::source.
Sourcepub fn verify_partition(&self) -> Result<(), &'static str>
pub fn verify_partition(&self) -> Result<(), &'static str>
Verify the ownership partition satisfies the P1
invariants: union covers [0, source.len()) exactly,
ranges are pairwise disjoint, each range is half-open
and within bounds. Returns Ok(()) on success or an
Err(&'static str) describing the first violation.
Used by integration tests and by parse itself when
the debug_assertions cfg flag is enabled. Production
callers do not need to invoke this; it exists to surface
parser regressions during testing.
Sourcepub fn kind(&self) -> DocumentKind
pub fn kind(&self) -> DocumentKind
The DocumentKind of this document.
Sourcepub fn todo_state(&self) -> Option<TodoState>
pub fn todo_state(&self) -> Option<TodoState>
For Todo documents, the parsed checkbox state. None for
non-Todo documents and for Todo documents whose title has
no [ ]/[x] prefix (permissive acceptance).
Sourcepub fn title(&self) -> Option<&[u8]>
pub fn title(&self) -> Option<&[u8]>
The raw title line bytes (including trailing newline);
None if no valid ATX H1 title.
Sourcepub fn title_str(&self) -> Option<Result<&str, Utf8Error>>
pub fn title_str(&self) -> Option<Result<&str, Utf8Error>>
Option<Result<&str, std::str::Utf8Error>> view of the
title. None for no title; Some(Ok(_)) for valid UTF-8;
Some(Err(_)) for invalid UTF-8.
For Note documents, the raw tags prefix line bytes
(including trailing newline); None otherwise.
Sourcepub fn tag_section(&self) -> Option<&[u8]>
pub fn tag_section(&self) -> Option<&[u8]>
For Todo/Bookmark documents, the raw tags-section bytes
(the entire H2 Tags section including its trailing
newline); None otherwise.
Iterator over tag token byte spans (&[u8]). Tokens come
from tags_prefix_range for Note documents and from
tag_section_range for Todo/Bookmark documents. Spans
reference bytes owned by the source.
Iterator yielding Result<&str, std::str::Utf8Error> per
tag token.
Sourcepub fn tag_token_spans(&self) -> Vec<Range<usize>>
pub fn tag_token_spans(&self) -> Vec<Range<usize>>
All tag token spans across the document. For Note,
tokens come from tags_prefix_range; for Todo/Bookmark,
from tag_section_range. Spans reference bytes owned by
the source and SHALL NOT themselves own bytes.
Sourcepub fn body_ranges(&self) -> Vec<Range<usize>>
pub fn body_ranges(&self) -> Vec<Range<usize>>
Body partition ranges in source order (half-open byte offsets).
Sourcepub fn body(&self) -> BodyFragments<'_> ⓘ
pub fn body(&self) -> BodyFragments<'_> ⓘ
Iterator over body byte ranges (in source order).
Sourcepub fn body_bytes(&self) -> Vec<u8> ⓘ
pub fn body_bytes(&self) -> Vec<u8> ⓘ
Concatenated body fragment bytes in source order (fingerprint domain).
Sourcepub fn title_byte_range(&self) -> Option<Range<usize>>
pub fn title_byte_range(&self) -> Option<Range<usize>>
Title line byte range when present (includes trailing newline).
Tags-prefix (Note) or tags-section (Todo/Bookmark) byte range.