Skip to main content

MarkdownStreamer

Struct MarkdownStreamer 

Source
pub struct MarkdownStreamer { /* private fields */ }
Expand description

Incremental Markdown serializer: feed finalized, in-document-order batches of Nodes and receive Markdown chunks whose concatenation is byte-identical to [to_markdown_images] over the same nodes. This is the streaming counterpart of the buffered serializer — used to emit a document’s Markdown in chunks (e.g. page by page, as the parallel PDF pipeline finishes pages) instead of building the whole string up front.

Only ImageMode::Placeholder and ImageMode::Embedded are streamable: ImageMode::Referenced needs a side-channel for the image bytes, which only the buffered [to_markdown_images] provides.

Each push must contain whole blocks in reading order: a caller must not split a run of list items across two pushes (the run would render as two separate lists). Finalized PDF page batches already satisfy this.

Implementations§

Source§

impl MarkdownStreamer

Source

pub fn new(strict: bool, images: ImageMode, compact_tables: bool) -> Self

Create a streamer. compact_tables mirrors DoclingDocument::compact_tables.

Source

pub fn push(&mut self, nodes: &[Node], links: &[(String, String)]) -> String

Render one finalized batch of nodes (plus any links recovered from the same span, in document order) into the next Markdown chunk. Returns an empty string when the batch produces no output (e.g. empty tables/pictures), in which case nothing should be written.

Source

pub fn finish(self) -> String

Emit the trailing newline that finishes the document (empty if no content was produced). Call exactly once, after the final push.

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