Skip to main content

Document

Struct Document 

Source
pub struct Document {
    pub annotations: Vec<Annotation>,
    pub root: Session,
}

Fields§

§annotations: Vec<Annotation>§root: Session

Implementations§

Source§

impl Document

Source

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

Source

pub fn new() -> Self

Source

pub fn with_content(content: Vec<ContentItem>) -> Self

Source

pub fn from_root(root: Session) -> Self

Construct a document from an existing root session.

Source

pub fn with_annotations_and_content( annotations: Vec<Annotation>, content: Vec<ContentItem>, ) -> Self

Source

pub fn with_root_location(self, location: Range) -> Self

Source

pub fn root_session(&self) -> &Session

Source

pub fn root_session_mut(&mut self) -> &mut Session

Source

pub fn into_root(self) -> Session

Source

pub fn title(&self) -> &str

Get the document title.

This delegates to the root session’s title.

Source

pub fn set_title(&mut self, title: String)

Set the document title.

This updates the root session’s title.

Source

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

Source

pub fn element_at(&self, pos: Position) -> Option<&ContentItem>

Returns the deepest (most nested) element that contains the position

Source

pub fn visual_line_at(&self, pos: Position) -> Option<&ContentItem>

Returns the visual line element at the given position

Source

pub fn block_element_at(&self, pos: Position) -> Option<&ContentItem>

Returns the block element at the given position

Source

pub fn annotations(&self) -> &[Annotation]

All annotations attached directly to the document (document-level metadata).

Source

pub fn annotations_mut(&mut self) -> &mut Vec<Annotation>

Mutable access to document-level annotations.

Source

pub fn iter_annotations(&self) -> Iter<'_, Annotation>

Iterate over document-level annotation blocks in source order.

Source

pub fn iter_annotation_contents(&self) -> impl Iterator<Item = &ContentItem>

Iterate over all content items nested inside document-level annotations.

Source

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
}
Source

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
}
Source

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
        }
        _ => {}
    }
}
Source

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

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§

Source§

impl AstNode for Document

Source§

fn node_type(&self) -> &'static str

Source§

fn display_label(&self) -> String

Source§

fn range(&self) -> &Range

Source§

fn accept(&self, visitor: &mut dyn Visitor)

Accept a visitor for traversing this node and its children
Source§

fn start_position(&self) -> Position

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Document

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Document

Source§

fn eq(&self, other: &Document) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Runnable<Document, Document> for AttachAnnotations

Source§

fn run(&self, input: Document) -> Result<Document, TransformError>

Execute this transformation on the input
Source§

impl Runnable<Session, Document> for AttachRoot

Source§

fn run(&self, root: Session) -> Result<Document, TransformError>

Execute this transformation on the input
Source§

impl StructuralPartialEq for Document

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more