Skip to main content

StackTrackingSink

Struct StackTrackingSink 

Source
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 Text event arrives outside any content-bearing block, a StartParagraph is 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>

Source

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.

Source

pub fn is_inside(&self, kind: BlockKind) -> bool

Returns true if the given block kind is anywhere in the current nesting stack.

Source

pub fn new(sink: S) -> Self

Creates a new stack-tracking wrapper around the given sink.

Source

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.

Trait Implementations§

Source§

impl<S: EventSink> EventSink for StackTrackingSink<S>

Source§

fn finish(self) -> Result<()>

Flush any buffered output and finalize the document. Read more
Source§

fn handle_event(&mut self, event: Event) -> Result<()>

Process one event from the stream. Read more

Auto Trait Implementations§

§

impl<S> Freeze for StackTrackingSink<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for StackTrackingSink<S>
where S: RefUnwindSafe,

§

impl<S> Send for StackTrackingSink<S>
where S: Send,

§

impl<S> Sync for StackTrackingSink<S>
where S: Sync,

§

impl<S> Unpin for StackTrackingSink<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for StackTrackingSink<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for StackTrackingSink<S>
where S: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.