Expand description
Core data model for docling.rs.
This crate is the Rust counterpart of the docling-core Python package: it
owns the unified DoclingDocument representation that every backend
produces and every serializer consumes. Keeping it dependency-light and
separate from the conversion logic mirrors the Python split between
docling-core (the schema) and docling (the converters).
Phase 0 models a simplified, linear node tree that is enough to round-trip
through Markdown. The faithful, $ref-based schema that matches
docling-core’s JSON wire format lands in Phase 1 (see docs/MIGRATION.md).
Re-exports§
pub use confidence::ConfidenceReport;pub use confidence::PageConfidence;pub use confidence::QualityGrade;pub use metadata::DocumentMetadata;pub use metadata::GpsPosition;pub use metadata::MetadataOutput;pub use redact::CustomPattern;pub use redact::ImageRedaction;pub use redact::PiiDetector;pub use redact::PiiKind;pub use redact::RedactionOptions;pub use redact::RedactionReport;pub use redact::Replacement;
Modules§
- assets
- Runtime-asset path resolution shared by every crate.
- base64
- Minimal standard-alphabet Base64 codec (RFC 4648):
encodefor embedding image bytes asdata:URIs,decodefor reading them back out — avoids a dependency for the two things we need. - chunker
- Document chunking for RAG pipelines — the Rust port of docling-core’s
docling_core.transforms.chunker. - confidence
- Conversion-confidence report — the Rust counterpart of docling’s
ConfidenceReport/PageConfidenceScores(docling.datamodel.base_models, surfaced per conversion by Python docling-serve v1.25+, #183). - doctags
- DocTags reader (issues #152 / #77): the token markup docling’s VLMs
(granite-docling / SmolDocling) emit, parsed into a
DoclingDocument. - env
- Environment-variable helpers shared by every crate in the workspace.
- jpeg
- A JPEG decoder that reproduces libjpeg(-turbo)’s output byte for byte —
what pdfium’s
DCTDecodeproduces (core/fxcodec/jpeg, libjpeg at its defaults: theJDCT_ISLOWinteger IDCT, “fancy” triangle-filter chroma upsampling, the 16.16 fixed-point YCbCr→RGB tables ofjdcolor.c). - metadata
- Document metadata (#679): what a file says about itself — an EPUB’s
Dublin Core, an Office package’s core and application properties, an
ODF
meta.xml, a photo’s EXIF, an audio file’s tags, a PDF’s Info dictionary — read intoDocumentMetadataon the document, and written out on request as ametadataobject in the JSON or as YAML front matter at the top of the Markdown (MetadataOutput). Nothing is written by default, so every export stays byte for byte what it was. - pandoc
- Pandoc AST output (
--to pandoc, #515): the document as the JSON serialization of Pandoc’sPandoctype (pandoc -f json), which hands docling.rs’s parsing to every Pandoc writer — DOCX, ODT, EPUB, RST, Org, Typst, AsciiDoc, … — throughdocling-rs in.pdf --to pandoc | pandoc -f json -t docx -o out.docx. - redact
- Opt-in PII redaction of a
DoclingDocument(#621). - tree
- docling’s item tree, for a backend that knows the exact shape upstream gives a document and wants the JSON export to reproduce it.
Macros§
- debug_
log eprintln!gated onenv::debug_enabled— the quiet diagnostics channel (DOCLING_RS_DEBUG=1). Callers keep their owndocling-<crate>:message prefixes; the macro only owns the gate.
Structs§
- Content
Layers - A set of content layers,
bodyincluded — docling-core’sset[ContentLayer](HTMLParams.layers,export_to_html(included_content_layers=…)), wherebodyis a member like any other.Defaultis docling’sDEFAULT_CONTENT_LAYERS: body only, so an export built with it is unchanged from before layers could be chosen (#499). - Docling
Document - The unified, format-agnostic document produced by every backend.
- Field
Item - One entry of a
Node::FieldRegion: a marker/key/value triple, any of which may be absent. Mirrors docling’sfield_itemwith itsmarker/field_key/field_valuechild texts. - Graph
Cell - One node of a
Node::KeyValueGraph— docling-core’sGraphCell. - Graph
Link - One edge of a
Node::KeyValueGraph— docling-core’sGraphLink. - Html
Export Options - Options of the HTML export (
DoclingDocument::export_to_html_with): docling-core’sHTMLParamssubset the port honours.Defaultis upstream’s default export — placeholder images,artifactsas the referenced-image directory, the body layer only. - Inline
Run - One styled segment of a
Node::InlineGroup— the docling.rs analogue of aTextIteminside anInlineGroup, carrying the ancestor formatting docling tracks.textis already whitespace-normalized/trimmed (one segment per source text node). A hyperlink is intentionally not stored: DocLang drops the target inside inline scope, keeping only the anchor text. - List
Item Dclx - DocLang-only content for a
Node::ListItemwhose DocLang form differs from its flat Markdowntext(seeNode::ListItem::dclx).orderedpicks the enclosing<list>kind,markerthe<ldiv><marker>; content isruns(structured equations/formatting) when non-empty, elsetextre-parsed for inline markers. - Markdown
Export Options - Options of the Markdown export
(
DoclingDocument::export_to_markdown_with_options, #599): the docling-coreMarkdownParamsthe port honours beyond the image mode.Defaultis upstream’s default export — placeholder images,artifactsas the referenced-image directory, the body layer only, no picture traversal, HTML and underscore escaping on,<!-- image -->— so a document exported with it is byte-identical toDoclingDocument::export_to_markdown. - Markdown
Streamer - 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. - Picture
Class - One DocumentPictureClassifier prediction — docling-core’s
PictureClassificationClass(class_name+confidence). - Picture
Description - A picture’s text annotation — docling-core’s
PictureDescriptionData(text+provenance), the one shape upstream uses for every model that writes prose about a picture. The picture-OCR enrichment (#645) fills it with the lines the OCR engine read off the image,provenancenaming the engine (ppocr/tesseract) the way a VLM description names its model. - Picture
Image - An extracted picture’s raw encoded bytes plus its mimetype and pixel size —
the docling.rs analogue of docling-core’s
ImageRef. - Table
- A simple row-major table. By default
rows[0]is the header row; aTableStructureoverlay overrides that and adds column spans. - Table
Cell - One table cell as a first-class object (#240) — the Rust counterpart of
docling’s
TableCell: its text, page geometry, grid rectangle and header roles. Produced by the PDF TableFormer paths from the predicted OTSL structure;bboxis[l, t, r, b]in page points with a top-left origin. - Table
Structure - OTSL structure overlay for a
Table, parallel toTable::rows. - VttExport
Options - Options of the WebVTT export — docling-core’s
WebVTTParams.
Enums§
- Caption
Parent - Where a picture’s or table’s caption text item hangs in the docling-JSON
tree (#390). docling’s backends do not agree, and the JSON structure is
the only surface that shows it (Markdown, DocLang and LaTeX place a
caption by its item, whatever its parent): the PDF pipeline parents a
layout caption to the picture or table it belongs to, while every
declarative backend creates the caption with
doc.add_text(label=CAPTION)and no parent — the document body — even when the item itself sits in a group or under a section header (JATS, LaTeX, HTML, Markdown, EPUB, AsciiDoc all do). The office backends hang a chart’s title caption off the chart’s container (the sheet group, the slide, docx’s current parent, docling#4190) — that isNode::Chart’s own path, not this choice. A backend that adds a new captioned item picks the variant matching upstream’sadd_textcall for that format; the default is upstream’s default. - Content
Layer - A DocLang content layer other than the default
body(seeNode::Furniture). - DocItem
Label - Semantic role of a document item, mirroring docling-core’s
DocItemLabel. - Encryption
Error - Why an encrypted document could not be opened.
- Image
Mode - How pictures are rendered (mirrors docling-core’s
ImageRefMode). - Node
- A single piece of document content.
- Script
- Vertical text position of an
InlineRun— docling’sScript.
Functions§
- code_
language_ label - Map a fence language to docling’s
CodeLanguageLabel(case-insensitive), elseunknown. docling’sCodeLanguageLabelfor a language name (unknownwhen it is not one docling knows) — the mapping the JSONcode_languagefield uses, for a backend that wants to test a hint before storing it. - inline_
paragraph_ node - Build the
Nodefor a paragraph of inline content from its structuredrunsand Markdown text, applying docling’sInlineGroupboundary: - inline_
runs_ from_ markdown - Parse a docling-legacy Markdown string into structured
InlineRuns for aNode::InlineGroup. Handles the marker set docling emits —***,**,*,~~,`,[t](u)— recursively so nested markers combine formatting, and splits plain text on newlines (docling’s<br>/ text-node boundaries become separate runs). Underline and sub/superscript have no Markdown representation and therefore never appear via this path.