pub struct Document {
pub annotations: Vec<Annotation>,
pub root: Session,
}Fields§
§annotations: Vec<Annotation>§root: SessionImplementations§
Source§impl Document
impl Document
Sourcepub fn diagnostics(&self) -> Vec<Diagnostic>
pub fn diagnostics(&self) -> Vec<Diagnostic>
Get all diagnostics for this document
This collects diagnostics from various validation checks:
- Broken references (footnotes, citations, session links)
- Malformed structures (single-item lists, etc.)
- Invalid annotation syntax
§Example
let doc = parse_document(source)?;
let diagnostics = doc.diagnostics();
for diag in diagnostics {
eprintln!("{}", diag);
}Source§impl Document
impl Document
pub fn new() -> Self
pub fn with_content(content: Vec<ContentItem>) -> Self
pub fn with_annotations_and_content( annotations: Vec<Annotation>, content: Vec<ContentItem>, ) -> Self
pub fn with_root_location(self, location: Range) -> Self
pub fn root_session(&self) -> &Session
pub fn root_session_mut(&mut self) -> &mut Session
pub fn into_root(self) -> Session
Sourcepub fn title(&self) -> &str
pub fn title(&self) -> &str
Get the document title.
This delegates to the root session’s title.
Sourcepub fn set_title(&mut self, title: String)
pub fn set_title(&mut self, title: String)
Set the document title.
This updates the root session’s title.
Sourcepub fn node_path_at_position(&self, pos: Position) -> Vec<&dyn AstNode>
pub fn node_path_at_position(&self, pos: Position) -> Vec<&dyn AstNode>
Returns the path of nodes at the given position, starting from the document
Sourcepub fn element_at(&self, pos: Position) -> Option<&ContentItem>
pub fn element_at(&self, pos: Position) -> Option<&ContentItem>
Returns the deepest (most nested) element that contains the position
Sourcepub fn visual_line_at(&self, pos: Position) -> Option<&ContentItem>
pub fn visual_line_at(&self, pos: Position) -> Option<&ContentItem>
Returns the visual line element at the given position
Sourcepub fn block_element_at(&self, pos: Position) -> Option<&ContentItem>
pub fn block_element_at(&self, pos: Position) -> Option<&ContentItem>
Returns the block element at the given position
Sourcepub fn annotations(&self) -> &[Annotation]
pub fn annotations(&self) -> &[Annotation]
All annotations attached directly to the document (document-level metadata).
Sourcepub fn annotations_mut(&mut self) -> &mut Vec<Annotation>
pub fn annotations_mut(&mut self) -> &mut Vec<Annotation>
Mutable access to document-level annotations.
Sourcepub fn iter_annotations(&self) -> Iter<'_, Annotation>
pub fn iter_annotations(&self) -> Iter<'_, Annotation>
Iterate over document-level annotation blocks in source order.
Sourcepub fn iter_annotation_contents(&self) -> impl Iterator<Item = &ContentItem>
pub fn iter_annotation_contents(&self) -> impl Iterator<Item = &ContentItem>
Iterate over all content items nested inside document-level annotations.
Sourcepub fn find_annotation_by_label(&self, label: &str) -> Option<&Annotation>
pub fn find_annotation_by_label(&self, label: &str) -> Option<&Annotation>
Find the first annotation with a matching label.
This searches recursively through all annotations in the document, including both document-level annotations and annotations in the content tree.
§Arguments
label- The label string to search for
§Returns
The first annotation whose label matches exactly, or None if not found.
§Example
// Find annotation with label "42" for reference [42]
if let Some(annotation) = document.find_annotation_by_label("42") {
// Jump to this annotation in go-to-definition
}Sourcepub fn find_annotations_by_label(&self, label: &str) -> Vec<&Annotation>
pub fn find_annotations_by_label(&self, label: &str) -> Vec<&Annotation>
Find all annotations with a matching label.
This searches recursively through all annotations in the document, including both document-level annotations and annotations in the content tree.
§Arguments
label- The label string to search for
§Returns
A vector of all annotations whose labels match exactly.
§Example
// Find all annotations labeled "note"
let notes = document.find_annotations_by_label("note");
for note in notes {
// Process each note annotation
}Sourcepub fn iter_all_references(
&self,
) -> Box<dyn Iterator<Item = ReferenceInline> + '_>
pub fn iter_all_references( &self, ) -> Box<dyn Iterator<Item = ReferenceInline> + '_>
Iterate all inline references at any depth.
This method recursively walks the document tree, parses inline content, and yields all reference inline nodes (e.g., [42], [@citation], [^note]).
§Returns
An iterator of references to ReferenceInline nodes
§Example
for reference in document.iter_all_references() {
match &reference.reference_type {
ReferenceType::FootnoteNumber { number } => {
// Find annotation with this number
}
ReferenceType::Citation(data) => {
// Process citation
}
_ => {}
}
}Sourcepub fn find_references_to(&self, target: &str) -> Vec<ReferenceInline>
pub fn find_references_to(&self, target: &str) -> Vec<ReferenceInline>
Find all references to a specific target label.
This method searches for inline references that point to the given target.
For example, find all [42] references when looking for footnote “42”.
§Arguments
target- The target label to search for
§Returns
A vector of references to ReferenceInline nodes that match the target
§Example
// Find all references to footnote "42"
let refs = document.find_references_to("42");
println!("Found {} references to footnote 42", refs.len());Source§impl Document
impl Document
Sourcepub fn find_all_links(&self) -> Vec<DocumentLink>
pub fn find_all_links(&self) -> Vec<DocumentLink>
Find all links in the entire document
This searches the entire document tree to find all clickable links:
- URL references in text
- File references in text
- Verbatim block src parameters
§Returns
Vector of all links found in the document
§Example
let doc = parse_document(source)?;
let links = doc.find_all_links();
for link in links {
// Make link clickable in LSP
send_document_link(link.range, link.target);
}Trait Implementations§
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more