Skip to main content

Crate docling_core

Crate docling_core 

Source
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): encode for embedding image bytes as data: URIs, decode for 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 DCTDecode produces (core/fxcodec/jpeg, libjpeg at its defaults: the JDCT_ISLOW integer IDCT, “fancy” triangle-filter chroma upsampling, the 16.16 fixed-point YCbCr→RGB tables of jdcolor.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 into DocumentMetadata on the document, and written out on request as a metadata object 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’s Pandoc type (pandoc -f json), which hands docling.rs’s parsing to every Pandoc writer — DOCX, ODT, EPUB, RST, Org, Typst, AsciiDoc, … — through docling-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 on env::debug_enabled — the quiet diagnostics channel (DOCLING_RS_DEBUG=1). Callers keep their own docling-<crate>: message prefixes; the macro only owns the gate.

Structs§

ContentLayers
A set of content layers, body included — docling-core’s set[ContentLayer] (HTMLParams.layers, export_to_html(included_content_layers=…)), where body is a member like any other. Default is docling’s DEFAULT_CONTENT_LAYERS: body only, so an export built with it is unchanged from before layers could be chosen (#499).
DoclingDocument
The unified, format-agnostic document produced by every backend.
FieldItem
One entry of a Node::FieldRegion: a marker/key/value triple, any of which may be absent. Mirrors docling’s field_item with its marker / field_key / field_value child texts.
GraphCell
One node of a Node::KeyValueGraph — docling-core’s GraphCell.
GraphLink
One edge of a Node::KeyValueGraph — docling-core’s GraphLink.
HtmlExportOptions
Options of the HTML export (DoclingDocument::export_to_html_with): docling-core’s HTMLParams subset the port honours. Default is upstream’s default export — placeholder images, artifacts as the referenced-image directory, the body layer only.
InlineRun
One styled segment of a Node::InlineGroup — the docling.rs analogue of a TextItem inside an InlineGroup, carrying the ancestor formatting docling tracks. text is 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.
ListItemDclx
DocLang-only content for a Node::ListItem whose DocLang form differs from its flat Markdown text (see Node::ListItem::dclx). ordered picks the enclosing <list> kind, marker the <ldiv><marker>; content is runs (structured equations/formatting) when non-empty, else text re-parsed for inline markers.
MarkdownExportOptions
Options of the Markdown export (DoclingDocument::export_to_markdown_with_options, #599): the docling-core MarkdownParams the port honours beyond the image mode. Default is upstream’s default export — placeholder images, artifacts as 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 to DoclingDocument::export_to_markdown.
MarkdownStreamer
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.
PictureClass
One DocumentPictureClassifier prediction — docling-core’s PictureClassificationClass (class_name + confidence).
PictureDescription
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, provenance naming the engine (ppocr / tesseract) the way a VLM description names its model.
PictureImage
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; a TableStructure overlay overrides that and adds column spans.
TableCell
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; bbox is [l, t, r, b] in page points with a top-left origin.
TableStructure
OTSL structure overlay for a Table, parallel to Table::rows.
VttExportOptions
Options of the WebVTT export — docling-core’s WebVTTParams.

Enums§

CaptionParent
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 is Node::Chart’s own path, not this choice. A backend that adds a new captioned item picks the variant matching upstream’s add_text call for that format; the default is upstream’s default.
ContentLayer
A DocLang content layer other than the default body (see Node::Furniture).
DocItemLabel
Semantic role of a document item, mirroring docling-core’s DocItemLabel.
EncryptionError
Why an encrypted document could not be opened.
ImageMode
How pictures are rendered (mirrors docling-core’s ImageRefMode).
Node
A single piece of document content.
Script
Vertical text position of an InlineRun — docling’s Script.

Functions§

code_language_label
Map a fence language to docling’s CodeLanguageLabel (case-insensitive), else unknown. docling’s CodeLanguageLabel for a language name (unknown when it is not one docling knows) — the mapping the JSON code_language field uses, for a backend that wants to test a hint before storing it.
inline_paragraph_node
Build the Node for a paragraph of inline content from its structured runs and Markdown text, applying docling’s InlineGroup boundary:
inline_runs_from_markdown
Parse a docling-legacy Markdown string into structured InlineRuns for a Node::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.