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
impl MarkdownStreamer
Sourcepub fn new(strict: bool, images: ImageMode, compact_tables: bool) -> Self
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.
Sourcepub fn with_artifacts(
strict: bool,
images: ImageMode,
compact_tables: bool,
artifacts_dir: &str,
) -> Self
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
 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.
Sourcepub fn take_artifacts(&mut self) -> Vec<(String, Vec<u8>)>
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.
Sourcepub fn push(&mut self, nodes: &[Node], links: &[(String, String)]) -> String
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.