pub struct StackTrackingSink<S: EventSink> { /* private fields */ }Expand description
A wrapper around any EventSink that tracks the nesting stack of open block-level containers
and performs event-stream normalization.
This sink maintains a stack of BlockKind values representing currently open containers.
Use the query methods to inspect the current nesting state.
§Normalization Behavior
- Auto-insert: If a
Textevent arrives outside any content-bearing block, aStartParagraphis automatically inserted before it. - Auto-close: On
EndDocument, all remaining open blocks are closed in reverse order. When an End event targets a block deeper in the stack, intervening blocks are auto-closed first. Auto-inserted paragraphs are closed before new block-level Start events. - Validation: An End event that does not match any open block on the stack returns
Error::InvalidSequence.
Implementations§
Source§impl<S: EventSink> StackTrackingSink<S>
impl<S: EventSink> StackTrackingSink<S>
Sourcepub fn has_open_content(&self) -> bool
pub fn has_open_content(&self) -> bool
Returns true if the stack contains any content-bearing block.
Content-bearing blocks are: BlockKind::Heading, BlockKind::Paragraph,
BlockKind::Preformatted, BlockKind::Link, BlockKind::DefinitionTerm.
Note: BlockKind::Blockquote is NOT content-bearing because block quotes contain
block elements (paragraphs, headings, etc.), not inline text directly. Text inside
a block quote without an explicit paragraph triggers auto-paragraph insertion.
Note: BlockKind::OrderedListItem, BlockKind::UnorderedListItem, BlockKind::TableCell, BlockKind::TableHeader,
and BlockKind::DefinitionDetail are NOT content-bearing despite being able to
contain inline content per EVENTS.md. This is because downstream writers like
BlockNoteWriter rely on auto-paragraph insertion for these container types.
Sourcepub fn is_inside(&self, kind: BlockKind) -> bool
pub fn is_inside(&self, kind: BlockKind) -> bool
Returns true if the given block kind is anywhere in the current nesting stack.
Sourcepub fn stack(&self) -> &[BlockKind]
pub fn stack(&self) -> &[BlockKind]
Returns a slice of the current nesting stack.
The first element is the outermost container (typically BlockKind::Document),
and the last element is the innermost currently open container.