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: RangeImplementations§
Source§impl Session
impl Session
pub fn new(title: TextContent, children: Vec<SessionContent>) -> Self
pub fn with_title(title: String) -> Self
Sourcepub fn annotations(&self) -> &[Annotation]
pub fn annotations(&self) -> &[Annotation]
Annotations attached to this session header/content block.
Sourcepub fn header_location(&self) -> Option<&Range>
pub fn header_location(&self) -> Option<&Range>
Range covering only the session title line, if available.
Sourcepub fn body_location(&self) -> Option<Range>
pub fn body_location(&self) -> Option<Range>
Bounding range covering only the session’s children.
Sourcepub fn title_text(&self) -> &str
pub fn title_text(&self) -> &str
Sourcepub fn full_title(&self) -> &str
pub fn full_title(&self) -> &str
Sourcepub fn annotations_mut(&mut self) -> &mut Vec<Annotation>
pub fn annotations_mut(&mut self) -> &mut Vec<Annotation>
Mutable access to session annotations.
Sourcepub fn iter_annotations(&self) -> Iter<'_, Annotation>
pub fn iter_annotations(&self) -> Iter<'_, Annotation>
Iterate over 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 attached annotations.
Sourcepub fn iter_items(&self) -> impl Iterator<Item = &ContentItem>
pub fn iter_items(&self) -> impl Iterator<Item = &ContentItem>
Iterate over immediate content items
Sourcepub fn iter_paragraphs(&self) -> impl Iterator<Item = &Paragraph>
pub fn iter_paragraphs(&self) -> impl Iterator<Item = &Paragraph>
Iterate over immediate paragraph children
Sourcepub fn iter_sessions(&self) -> impl Iterator<Item = &Session>
pub fn iter_sessions(&self) -> impl Iterator<Item = &Session>
Iterate over immediate session children
Sourcepub fn iter_lists(&self) -> impl Iterator<Item = &List>
pub fn iter_lists(&self) -> impl Iterator<Item = &List>
Iterate over immediate list children
Sourcepub fn iter_verbatim_blocks(&self) -> impl Iterator<Item = &Verbatim>
pub fn iter_verbatim_blocks(&self) -> impl Iterator<Item = &Verbatim>
Iterate over immediate verbatim block children
Sourcepub fn iter_all_nodes(&self) -> Box<dyn Iterator<Item = &ContentItem> + '_>
pub fn iter_all_nodes(&self) -> Box<dyn Iterator<Item = &ContentItem> + '_>
Iterate all nodes in the session tree (depth-first pre-order traversal)
Sourcepub fn iter_all_nodes_with_depth(
&self,
) -> Box<dyn Iterator<Item = (&ContentItem, usize)> + '_>
pub fn iter_all_nodes_with_depth( &self, ) -> Box<dyn Iterator<Item = (&ContentItem, usize)> + '_>
Iterate all nodes with their depth (0 = immediate children)
Sourcepub fn iter_paragraphs_recursive(
&self,
) -> Box<dyn Iterator<Item = &Paragraph> + '_>
pub fn iter_paragraphs_recursive( &self, ) -> Box<dyn Iterator<Item = &Paragraph> + '_>
Recursively iterate all paragraphs at any depth
Sourcepub fn iter_sessions_recursive(&self) -> Box<dyn Iterator<Item = &Session> + '_>
pub fn iter_sessions_recursive(&self) -> Box<dyn Iterator<Item = &Session> + '_>
Recursively iterate all sessions at any depth
Sourcepub fn iter_lists_recursive(&self) -> Box<dyn Iterator<Item = &List> + '_>
pub fn iter_lists_recursive(&self) -> Box<dyn Iterator<Item = &List> + '_>
Recursively iterate all lists at any depth
Sourcepub fn iter_verbatim_blocks_recursive(
&self,
) -> Box<dyn Iterator<Item = &Verbatim> + '_>
pub fn iter_verbatim_blocks_recursive( &self, ) -> Box<dyn Iterator<Item = &Verbatim> + '_>
Recursively iterate all verbatim blocks at any depth
Sourcepub fn iter_list_items_recursive(
&self,
) -> Box<dyn Iterator<Item = &ListItem> + '_>
pub fn iter_list_items_recursive( &self, ) -> Box<dyn Iterator<Item = &ListItem> + '_>
Recursively iterate all list items at any depth
Sourcepub fn iter_definitions_recursive(
&self,
) -> Box<dyn Iterator<Item = &Definition> + '_>
pub fn iter_definitions_recursive( &self, ) -> Box<dyn Iterator<Item = &Definition> + '_>
Recursively iterate all definitions at any depth
Sourcepub fn iter_annotations_recursive(
&self,
) -> Box<dyn Iterator<Item = &Annotation> + '_>
pub fn iter_annotations_recursive( &self, ) -> Box<dyn Iterator<Item = &Annotation> + '_>
Recursively iterate all annotations at any depth
Sourcepub fn first_paragraph(&self) -> Option<&Paragraph>
pub fn first_paragraph(&self) -> Option<&Paragraph>
Get the first paragraph (returns None if not found)
Sourcepub fn first_session(&self) -> Option<&Session>
pub fn first_session(&self) -> Option<&Session>
Get the first session (returns None if not found)
Sourcepub fn first_list(&self) -> Option<&List>
pub fn first_list(&self) -> Option<&List>
Get the first list (returns None if not found)
Sourcepub fn first_definition(&self) -> Option<&Definition>
pub fn first_definition(&self) -> Option<&Definition>
Get the first definition (returns None if not found)
Sourcepub fn first_annotation(&self) -> Option<&Annotation>
pub fn first_annotation(&self) -> Option<&Annotation>
Get the first annotation (returns None if not found)
Sourcepub fn first_verbatim(&self) -> Option<&Verbatim>
pub fn first_verbatim(&self) -> Option<&Verbatim>
Get the first verbatim block (returns None if not found)
Sourcepub fn expect_paragraph(&self) -> &Paragraph
pub fn expect_paragraph(&self) -> &Paragraph
Get the first paragraph, panicking if none found
Sourcepub fn expect_session(&self) -> &Session
pub fn expect_session(&self) -> &Session
Get the first session, panicking if none found
Sourcepub fn expect_list(&self) -> &List
pub fn expect_list(&self) -> &List
Get the first list, panicking if none found
Sourcepub fn expect_definition(&self) -> &Definition
pub fn expect_definition(&self) -> &Definition
Get the first definition, panicking if none found
Sourcepub fn expect_annotation(&self) -> &Annotation
pub fn expect_annotation(&self) -> &Annotation
Get the first annotation, panicking if none found
Sourcepub fn expect_verbatim(&self) -> &Verbatim
pub fn expect_verbatim(&self) -> &Verbatim
Get the first verbatim block, panicking if none found
Sourcepub fn find_paragraphs<F>(&self, predicate: F) -> Vec<&Paragraph>
pub fn find_paragraphs<F>(&self, predicate: F) -> Vec<&Paragraph>
Find all paragraphs matching a predicate
Sourcepub fn find_sessions<F>(&self, predicate: F) -> Vec<&Session>
pub fn find_sessions<F>(&self, predicate: F) -> Vec<&Session>
Find all sessions matching a predicate
Sourcepub fn find_lists<F>(&self, predicate: F) -> Vec<&List>
pub fn find_lists<F>(&self, predicate: F) -> Vec<&List>
Find all lists matching a predicate
Sourcepub fn find_definitions<F>(&self, predicate: F) -> Vec<&Definition>
pub fn find_definitions<F>(&self, predicate: F) -> Vec<&Definition>
Find all definitions matching a predicate
Sourcepub fn find_annotations<F>(&self, predicate: F) -> Vec<&Annotation>
pub fn find_annotations<F>(&self, predicate: F) -> Vec<&Annotation>
Find all annotations matching a predicate
Sourcepub fn find_nodes<F>(&self, predicate: F) -> Vec<&ContentItem>
pub fn find_nodes<F>(&self, predicate: F) -> Vec<&ContentItem>
Find all nodes matching a generic predicate
Sourcepub fn find_nodes_at_depth(&self, target_depth: usize) -> Vec<&ContentItem>
pub fn find_nodes_at_depth(&self, target_depth: usize) -> Vec<&ContentItem>
Find all nodes at a specific depth
Sourcepub fn find_nodes_in_depth_range(
&self,
min_depth: usize,
max_depth: usize,
) -> Vec<&ContentItem>
pub fn find_nodes_in_depth_range( &self, min_depth: usize, max_depth: usize, ) -> Vec<&ContentItem>
Find all nodes within a depth range
Sourcepub fn find_nodes_with_depth<F>(
&self,
target_depth: usize,
predicate: F,
) -> Vec<&ContentItem>
pub fn find_nodes_with_depth<F>( &self, target_depth: usize, predicate: F, ) -> Vec<&ContentItem>
Find nodes at a specific depth matching a predicate
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 find_nodes_at_position(&self, position: Position) -> Vec<&dyn AstNode>
pub fn find_nodes_at_position(&self, position: Position) -> Vec<&dyn AstNode>
Returns the deepest AST node at the given position, if any
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 this session
Sourcepub fn format_at_position(&self, position: Position) -> String
pub fn format_at_position(&self, position: Position) -> String
Formats information about nodes located at a given position
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 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
}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 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
}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 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
}
_ => {}
}
}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 = session.find_references_to("42");
println!("Found {} references to footnote 42", refs.len());Source§impl Session
impl Session
Sourcepub fn find_all_links(&self) -> Vec<DocumentLink>
pub fn find_all_links(&self) -> Vec<DocumentLink>
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 Container for Session
impl Container for Session
fn label(&self) -> &str
fn children(&self) -> &[ContentItem]
fn children_mut(&mut self) -> &mut Vec<ContentItem>
Source§impl VisualStructure for Session
impl VisualStructure for Session
Source§fn is_source_line_node(&self) -> bool
fn is_source_line_node(&self) -> bool
Source§fn has_visual_header(&self) -> bool
fn has_visual_header(&self) -> bool
Source§fn collapses_with_children(&self) -> bool
fn collapses_with_children(&self) -> bool
impl StructuralPartialEq for Session
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
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