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.

ImageMode::Placeholder and ImageMode::Embedded render inline. ImageMode::Referenced additionally hands each picture’s bytes out through take_artifacts — construct with with_artifacts and drain after every push so the bytes can be written to disk as pages finish instead of accumulating for the whole document (issue #80’s memory-bounded image handling).

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. For ImageMode::Referenced use with_artifacts.

Source

pub fn with_artifacts( strict: bool, images: ImageMode, compact_tables: bool, artifacts_dir: &str, ) -> Self

Like new but with the artifacts link prefix, allowing ImageMode::Referenced: pictures render as ![Image](<artifacts_dir>/image_NNNNNN.<ext>) and each push’s image bytes wait in take_artifacts for the caller to write. The concatenated chunks and the artifact list match the buffered [to_markdown_images] byte-for-byte.

Source

pub fn take_artifacts(&mut self) -> Vec<(String, Vec<u8>)>

The (relative path, bytes) of images rendered by pushes since the last drain (ImageMode::Referenced only — empty otherwise). Paths are relative to the Markdown file, i.e. they start with the configured artifacts dir.

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

Source§

type Output = T

Should always be Self
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.