Skip to main content

Session

Struct Session 

Source
pub struct Session {
    pub title: TextContent,
    pub marker: Option<SequenceMarker>,
    pub children: SessionContainer,
    pub annotations: Vec<Annotation>,
    pub location: Range,
}
Expand description

A session represents a hierarchical container with a title

Fields§

§title: TextContent§marker: Option<SequenceMarker>§children: SessionContainer§annotations: Vec<Annotation>§location: Range

Implementations§

Source§

impl Session

Source

pub fn new(title: TextContent, children: Vec<SessionContent>) -> Self

Source

pub fn with_title(title: String) -> Self

Source

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

Preferred builder

Source

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

Annotations attached to this session header/content block.

Source

pub fn header_location(&self) -> Option<&Range>

Range covering only the session title line, if available.

Source

pub fn body_location(&self) -> Option<Range>

Bounding range covering only the session’s children.

Source

pub fn title_text(&self) -> &str

Get the title text without the sequence marker

Returns the title with any leading sequence marker removed. For example, “1. Introduction” becomes “Introduction”.

§Examples
let session = parse_session("1. Introduction:\n\n    Content");
assert_eq!(session.title_text(), "Introduction");
Source

pub fn full_title(&self) -> &str

Get the full title including any sequence marker

Returns the complete title as it appears in the source, including any sequence marker prefix.

§Examples
let session = parse_session("1. Introduction:\n\n    Content");
assert_eq!(session.full_title(), "1. Introduction");
Source

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

Mutable access to session annotations.

Source

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

Iterate over annotation blocks in source order.

Source

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

Iterate over all content items nested inside attached annotations.

Source

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

Iterate over immediate content items

Source

pub fn iter_paragraphs(&self) -> impl Iterator<Item = &Paragraph>

Iterate over immediate paragraph children

Source

pub fn iter_sessions(&self) -> impl Iterator<Item = &Session>

Iterate over immediate session children

Source

pub fn iter_lists(&self) -> impl Iterator<Item = &List>

Iterate over immediate list children

Source

pub fn iter_verbatim_blocks(&self) -> impl Iterator<Item = &Verbatim>

Iterate over immediate verbatim block children

Source

pub fn iter_all_nodes(&self) -> Box<dyn Iterator<Item = &ContentItem> + '_>

Iterate all nodes in the session tree (depth-first pre-order traversal)

Source

pub fn iter_all_nodes_with_depth( &self, ) -> Box<dyn Iterator<Item = (&ContentItem, usize)> + '_>

Iterate all nodes with their depth (0 = immediate children)

Source

pub fn iter_paragraphs_recursive( &self, ) -> Box<dyn Iterator<Item = &Paragraph> + '_>

Recursively iterate all paragraphs at any depth

Source

pub fn iter_sessions_recursive(&self) -> Box<dyn Iterator<Item = &Session> + '_>

Recursively iterate all sessions at any depth

Source

pub fn iter_lists_recursive(&self) -> Box<dyn Iterator<Item = &List> + '_>

Recursively iterate all lists at any depth

Source

pub fn iter_verbatim_blocks_recursive( &self, ) -> Box<dyn Iterator<Item = &Verbatim> + '_>

Recursively iterate all verbatim blocks at any depth

Source

pub fn iter_list_items_recursive( &self, ) -> Box<dyn Iterator<Item = &ListItem> + '_>

Recursively iterate all list items at any depth

Source

pub fn iter_definitions_recursive( &self, ) -> Box<dyn Iterator<Item = &Definition> + '_>

Recursively iterate all definitions at any depth

Source

pub fn iter_annotations_recursive( &self, ) -> Box<dyn Iterator<Item = &Annotation> + '_>

Recursively iterate all annotations at any depth

Source

pub fn first_paragraph(&self) -> Option<&Paragraph>

Get the first paragraph (returns None if not found)

Source

pub fn first_session(&self) -> Option<&Session>

Get the first session (returns None if not found)

Source

pub fn first_list(&self) -> Option<&List>

Get the first list (returns None if not found)

Source

pub fn first_definition(&self) -> Option<&Definition>

Get the first definition (returns None if not found)

Source

pub fn first_annotation(&self) -> Option<&Annotation>

Get the first annotation (returns None if not found)

Source

pub fn first_verbatim(&self) -> Option<&Verbatim>

Get the first verbatim block (returns None if not found)

Source

pub fn expect_paragraph(&self) -> &Paragraph

Get the first paragraph, panicking if none found

Source

pub fn expect_session(&self) -> &Session

Get the first session, panicking if none found

Source

pub fn expect_list(&self) -> &List

Get the first list, panicking if none found

Source

pub fn expect_definition(&self) -> &Definition

Get the first definition, panicking if none found

Source

pub fn expect_annotation(&self) -> &Annotation

Get the first annotation, panicking if none found

Source

pub fn expect_verbatim(&self) -> &Verbatim

Get the first verbatim block, panicking if none found

Source

pub fn find_paragraphs<F>(&self, predicate: F) -> Vec<&Paragraph>
where F: Fn(&Paragraph) -> bool,

Find all paragraphs matching a predicate

Source

pub fn find_sessions<F>(&self, predicate: F) -> Vec<&Session>
where F: Fn(&Session) -> bool,

Find all sessions matching a predicate

Source

pub fn find_lists<F>(&self, predicate: F) -> Vec<&List>
where F: Fn(&List) -> bool,

Find all lists matching a predicate

Source

pub fn find_definitions<F>(&self, predicate: F) -> Vec<&Definition>
where F: Fn(&Definition) -> bool,

Find all definitions matching a predicate

Source

pub fn find_annotations<F>(&self, predicate: F) -> Vec<&Annotation>
where F: Fn(&Annotation) -> bool,

Find all annotations matching a predicate

Source

pub fn find_nodes<F>(&self, predicate: F) -> Vec<&ContentItem>
where F: Fn(&ContentItem) -> bool,

Find all nodes matching a generic predicate

Source

pub fn find_nodes_at_depth(&self, target_depth: usize) -> Vec<&ContentItem>

Find all nodes at a specific depth

Source

pub fn find_nodes_in_depth_range( &self, min_depth: usize, max_depth: usize, ) -> Vec<&ContentItem>

Find all nodes within a depth range

Source

pub fn find_nodes_with_depth<F>( &self, target_depth: usize, predicate: F, ) -> Vec<&ContentItem>
where F: Fn(&ContentItem) -> bool,

Find nodes at a specific depth matching a predicate

Source

pub fn count_by_type(&self) -> (usize, usize, usize, usize)

Count immediate children by type

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 find_nodes_at_position(&self, position: Position) -> Vec<&dyn AstNode>

Returns the deepest AST node at the given position, if any

Source

pub fn node_path_at_position(&self, pos: Position) -> Vec<&dyn AstNode>

Returns the path of nodes at the given position, starting from this session

Source

pub fn format_at_position(&self, position: Position) -> String

Formats information about nodes located at a given position

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 session 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) = session.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 session tree. Multiple annotations might share the same label.

§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 = session.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 session tree, parses inline content, and yields all reference inline nodes (e.g., [42], [@citation], [^note]).

Note: This method does not currently return source ranges for individual references. Use the paragraph’s location as a starting point for finding references in the source.

§Returns

An iterator of references to ReferenceInline nodes

§Example
for reference in session.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 = session.find_references_to("42");
println!("Found {} references to footnote 42", refs.len());
Source§

impl Session

Find all links at any depth in this session

This searches recursively through all content to find:

  • URL references: [https://example.com]
  • File references: [./path/to/file.txt]
  • Verbatim src parameters: src=./image.png
§Returns

Vector of all links found in this session and its descendants

§Example
let links = session.find_all_links();
for link in links {
    println!("Found {} link: {}", link.link_type, link.target);
}

Trait Implementations§

Source§

impl AstNode for Session

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 Session

Source§

fn clone(&self) -> Session

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 Container for Session

Source§

fn label(&self) -> &str

Source§

fn children(&self) -> &[ContentItem]

Source§

fn children_mut(&mut self) -> &mut Vec<ContentItem>

Source§

impl Debug for Session

Source§

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

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

impl Display for Session

Source§

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

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

impl PartialEq for Session

Source§

fn eq(&self, other: &Session) -> 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<Session, Document> for AttachRoot

Source§

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

Execute this transformation on the input
Source§

impl Runnable<Session, Session> for ParseInlines

Source§

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

Execute this transformation on the input
Source§

impl VisualStructure for Session

Source§

fn is_source_line_node(&self) -> bool

Whether this node corresponds to a line in the source document Read more
Source§

fn has_visual_header(&self) -> bool

Whether this node has a visual header line separate from its content Read more
Source§

fn collapses_with_children(&self) -> bool

Whether this is a homogeneous container whose children can collapse with parent icon Read more
Source§

impl StructuralPartialEq for Session

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