pub struct DoclingDocument {
pub name: String,
pub nodes: Vec<Node>,
pub strict_markdown: bool,
pub compact_tables: bool,
pub page_break_placeholder: Option<String>,
pub links: Vec<(String, String)>,
pub confidence: Option<ConfidenceReport>,
pub tree: Option<ItemTree>,
pub page_images: BTreeMap<usize, PictureImage>,
}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.
page_break_placeholder: Option<String>Text the Markdown export inserts between two pages — docling-core’s
MarkdownParams.page_break_placeholder (e.g. "<!-- page break -->").
None (the default) omits page breaks from Markdown, as docling does.
Set by DocumentConverter::page_break_placeholder. See
[crate::markdown] for where a break lands (only between two rendered
blocks that sit on different pages, never leading or trailing).
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.
tree: Option<ItemTree>docling’s item tree, when the backend built one (the HTML backend
does): the JSON export serializes it instead of deriving a tree from
nodes, so the JSON carries upstream’s exact parent/child structure,
item numbering, inline groups, formatting and content layers. Every
other serializer reads nodes. See crate::tree.
page_images: BTreeMap<usize, PictureImage>Rendered page images by 1-based page number — docling’s
PageItem.image, filled by the PDF/image pipeline only when page
images are requested (docling’s generate_page_images, #520). The
JSON export writes each as the page’s image, so docling-core’s
TableItem.get_image / FormulaItem.get_image can crop from it.
Empty otherwise; no other export reads it.
Implementations§
Source§impl DoclingDocument
impl DoclingDocument
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_table_cell_markdown(&self) -> String
pub fn export_to_table_cell_markdown(&self) -> String
Markdown for this document as the content of a rich table cell
(docling-core’s in_table_cell serialization, docling-core#540):
headings render as plain text since Markdown tables can’t hold them.
Backends build a sub-document per rich cell and flatten this into the
cell text; no trailing newline.
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_latex(&self) -> String
pub fn export_to_latex(&self) -> String
Serialize to a complete LaTeX document — the Rust counterpart of
docling-core’s LaTeXDocSerializer with default parameters (docling
2.124’s --to latex, #317). No trailing newline, like the upstream
CLI’s <stem>.tex.
Sourcepub fn export_to_pandoc_json(&self) -> String
pub fn export_to_pandoc_json(&self) -> String
Serialize to Pandoc’s AST as JSON (pandoc -f json, #515) with the
default options: pictures as captioned figures without image data,
body layer only, the PANDOC_API_VERSION
API. One line, no trailing newline. See crate::pandoc.
Sourcepub fn export_to_pandoc_json_with(
&self,
options: &PandocExportOptions,
) -> Result<PandocOutput, PandocError>
pub fn export_to_pandoc_json_with( &self, options: &PandocExportOptions, ) -> Result<PandocOutput, PandocError>
Pandoc JSON per options (image mode, artifacts directory, content
layers, required API version). Returns the JSON and, for
ImageMode::Referenced, the (path, bytes) image files; an
unsupported api_version is an error.
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_doclang_with_assets(&self) -> (String, Vec<(String, Vec<u8>)>)
pub fn export_to_doclang_with_assets(&self) -> (String, Vec<(String, Vec<u8>)>)
Self::export_to_doclang plus the picture assets its
<src uri="assets/image_….png"/> references name, as (path, bytes)
in document order — the parts docling’s save_as_doclang_archive
stores next to document.xml. PNG and JPEG pictures come back as PNG
(a JPEG re-encoded from its libjpeg-decoded pixels); other encodings
keep their own bytes for the archive writer to convert.
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.
Sourcepub fn export_to_html(&self) -> String
pub fn export_to_html(&self) -> String
A complete HTML document — docling-core’s HTMLDocSerializer with its
defaults (#492): pictures stay out (ImageRefMode.PLACEHOLDER, only
their captions and meta render). See export_to_html_with_images
for the embedded / referenced modes and [crate::html]’s module docs
for what is reproduced.
Sourcepub fn export_to_html_with_images(
&self,
image_mode: ImageMode,
artifacts_dir: &str,
) -> (String, Vec<(String, Vec<u8>)>)
pub fn export_to_html_with_images( &self, image_mode: ImageMode, artifacts_dir: &str, ) -> (String, Vec<(String, Vec<u8>)>)
HTML with pictures per image_mode: data: URIs when embedded, and
when referenced <img src> paths under artifacts_dir whose bytes come
back as (path, bytes) for the caller to write — the Markdown export’s
contract and file names.
Sourcepub fn export_to_html_with_layers(&self, layers: ContentLayers) -> String
pub fn export_to_html_with_layers(&self, layers: ContentLayers) -> String
HTML rendering the content layers — docling-core’s
export_to_html(included_content_layers=…) (#499). The default export
is body only; ContentLayers::BODY.with(ContentLayer::Furniture) adds
page headers/footers, .with(ContentLayer::Notes) reviewer comments,
ContentLayers::ALL is Python’s set(ContentLayer). An item on a
layer outside the set is skipped while its children are still walked,
and the items that do render go through the same serializers as the
body (a page header is a <p>, a comment a <p>, a header table a
<table>), exactly as upstream’s HTMLParams.layers behaves. Pictures
stay placeholders; see export_to_html_with for the full option set.
Sourcepub fn export_to_html_with(
&self,
options: &HtmlExportOptions,
) -> (String, Vec<(String, Vec<u8>)>)
pub fn export_to_html_with( &self, options: &HtmlExportOptions, ) -> (String, Vec<(String, Vec<u8>)>)
HTML per options — image mode, referenced-image directory and content
layers in one call; the other export_to_html* methods are
shorthands for it. Returns the HTML and, for
ImageMode::Referenced, the (path, bytes) artifacts.