pub struct DoclingDocument {
pub name: String,
pub nodes: Vec<Node>,
pub strict_markdown: bool,
pub compact_tables: bool,
pub links: Vec<(String, String)>,
pub confidence: Option<ConfidenceReport>,
}Expand description
The unified, format-agnostic document produced by every backend.
This is the heart of docling: backends parse their source format into a
DoclingDocument, and serializers turn it back into Markdown, HTML, JSON,
etc. Phase 0 uses a flat sequence of Nodes; the production schema will
match docling-core’s body-tree-with-references layout.
Fields§
§name: StringLogical document name (usually the input file stem).
nodes: Vec<Node>Top-level content, in reading order.
strict_markdown: boolDefault Markdown export mode for Self::export_to_markdown. false
(the default) reproduces docling’s legacy output byte-for-byte; true
emits cleaner, more conformant Markdown. Set by DocumentConverter.
compact_tables: boolEmit tables in the compact | a | b | / | - | - | form rather than
docling-core’s width-padded GitHub serializer. The PDF backend sets this
(its committed groundtruth corpus predates the padded serializer); DOCX/HTML
leave it false to match current published docling.
links: Vec<(String, String)>Hyperlinks recovered from the source, as (anchor_text, href) pairs in
document order. docling’s standard pipeline drops PDF link annotations, so
these are rendered as Markdown [anchor](href) only in strict mode
(legacy/docling output is left byte-for-byte unchanged). The PDF backend
populates this from pdfium link annotations; other backends leave it empty.
confidence: Option<ConfidenceReport>Conversion-confidence report (#183), populated by the PDF/image ML
pipeline; None for declarative conversions. Deliberately not
part of any document export (docling keeps it on the conversion
result, outside the document schema) — docling-serve surfaces it in
the HTTP response instead.
Implementations§
Source§impl DoclingDocument
impl DoclingDocument
Sourcepub fn new(name: impl Into<String>) -> DoclingDocument
pub fn new(name: impl Into<String>) -> DoclingDocument
Create an empty document with the given name.
Sourcepub fn tables(&self) -> impl Iterator<Item = &Table>
pub fn tables(&self) -> impl Iterator<Item = &Table>
Append a node.
The document’s top-level tables in reading order — the read half of
the post-extraction table API (#238). Node::Located wrappers (the
PDF pipeline attaches layout provenance that way) are looked through;
tables nested inside rich table cells (Table::cell_blocks) are not
traversed.
Sourcepub fn tables_mut(&mut self) -> impl Iterator<Item = &mut Table>
pub fn tables_mut(&mut self) -> impl Iterator<Item = &mut Table>
Mutable access to the document’s top-level tables, for repair
workflows (#238): locate a cell via Table::find_cell_by_bbox, fix
its text with Table::set_cell_text, then re-export — every
serializer reads the same grid.
pub fn push(&mut self, node: Node)
Sourcepub fn add_heading(&mut self, level: u8, text: impl Into<String>)
pub fn add_heading(&mut self, level: u8, text: impl Into<String>)
Convenience: append a heading.
Sourcepub fn add_paragraph(&mut self, text: impl Into<String>)
pub fn add_paragraph(&mut self, text: impl Into<String>)
Convenience: append a paragraph.
Sourcepub fn export_to_markdown(&self) -> String
pub fn export_to_markdown(&self) -> String
Serialize the document to Markdown.
The Rust equivalent of docling-core’s
DoclingDocument.export_to_markdown(). Uses Self::strict_markdown to
pick between docling-legacy output (default) and the cleaner, more
conformant variant.
Sourcepub fn export_to_markdown_with(&self, strict: bool) -> String
pub fn export_to_markdown_with(&self, strict: bool) -> String
Serialize to Markdown, explicitly choosing the mode regardless of
Self::strict_markdown. strict = true produces cleaner, more
conformant Markdown (code-fence languages preserved, no inline-run
spacing artifacts); strict = false reproduces docling’s legacy output.
Sourcepub fn export_to_json(&self) -> String
pub fn export_to_json(&self) -> String
Serialize to docling-core’s native JSON wire format (DoclingDocument
schema), pretty-printed — the Rust equivalent of
DoclingDocument.export_to_dict() / save_as_json(). The output loads
back into Python docling-core and round-trips to the same Markdown.
Sourcepub fn export_to_json_value(&self) -> Value
pub fn export_to_json_value(&self) -> Value
The same JSON wire format as Self::export_to_json, as a
serde_json::Value — for callers that append response-level extras
(docling-serve adds the confidence report, #183) before serializing.
Sourcepub fn export_to_doclang(&self) -> String
pub fn export_to_doclang(&self) -> String
Serialize to DocLang XML (<doclang version="0.7">…), the markup that
lives inside a .dclx archive — the Rust counterpart of docling-core’s
export_to_doclang() with default parameters. No trailing newline; the
archive writer appends exactly one.
Sourcepub fn export_to_markdown_with_images(
&self,
image_mode: ImageMode,
artifacts_dir: &str,
) -> (String, Vec<(String, Vec<u8>)>)
pub fn export_to_markdown_with_images( &self, image_mode: ImageMode, artifacts_dir: &str, ) -> (String, Vec<(String, Vec<u8>)>)
Serialize to Markdown with an explicit picture ImageMode (mirrors
docling’s image_mode). Returns the Markdown and, for
ImageMode::Referenced, the (relative-path, bytes) of each image the
caller should write next to the Markdown file. artifacts_dir is the
directory name used in referenced links.
Trait Implementations§
Source§impl Clone for DoclingDocument
impl Clone for DoclingDocument
Source§fn clone(&self) -> DoclingDocument
fn clone(&self) -> DoclingDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DoclingDocument
impl Debug for DoclingDocument
Source§impl PartialEq for DoclingDocument
impl PartialEq for DoclingDocument
impl StructuralPartialEq for DoclingDocument
Auto Trait Implementations§
impl Freeze for DoclingDocument
impl RefUnwindSafe for DoclingDocument
impl Send for DoclingDocument
impl Sync for DoclingDocument
impl Unpin for DoclingDocument
impl UnsafeUnpin for DoclingDocument
impl UnwindSafe for DoclingDocument
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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