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,
) -> MarkdownStreamer
pub fn new( strict: bool, images: ImageMode, compact_tables: bool, ) -> MarkdownStreamer
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,
) -> MarkdownStreamer
pub fn with_artifacts( strict: bool, images: ImageMode, compact_tables: bool, artifacts_dir: &str, ) -> MarkdownStreamer
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.
Auto Trait Implementations§
impl Freeze for MarkdownStreamer
impl RefUnwindSafe for MarkdownStreamer
impl Send for MarkdownStreamer
impl Sync for MarkdownStreamer
impl Unpin for MarkdownStreamer
impl UnsafeUnpin for MarkdownStreamer
impl UnwindSafe for MarkdownStreamer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more