Skip to main content

Module docling

Module docling 

Source
Expand description

The block model as a Docling DoclingDocument (#629).

A pipeline built on Docling reads its documents through docling-core’s DoclingDocument: it walks body, filters on label, cites prov and asks the table for its grid. This writes that document from our blocks, so such a pipeline can swap the converter and keep every line downstream of it. crates/pdf-python/tests/test_docling_document.py loads what this writes with docling-core’s own model and checks it comes back unchanged.

THE SCHEMA IS PINNED: DoclingDocument version SCHEMA_VERSION, as docling-core DOCLING_CORE_VERSION writes it (MIT, the Docling project). The test above installs exactly that version, so a schema that moves is a decision somebody makes here and not a surprise in a customer’s pipeline.

WHAT MAPS, block kind by block kind:

  • a paragraph is a text item;
  • a heading is a section_header with the block’s level (1 to 3);
  • a list item is a list_item inside a list group, enumerated where the document numbered it and with the marker written as N. or -. A nested item opens a group under the item above it, which is where Docling puts a sub-list;
  • a run of table cells is one table, its cells with their spans and column_header from the header row, and the grid Docling derives from them written out as Docling would derive it;
  • a running head and a running footer are page_header and page_footer under furniture, in the furniture content layer, so every Docling export that leaves the furniture out leaves them out too;
  • the half of a paragraph a page break cut off is not an item of its own: it is joined onto the paragraph it continues, which then carries one prov entry per page, each with the charspan of its own half.

PROVENANCE: page_no is 1-BASED, because Docling’s is – the one place this output disagrees with Block::page and with the page markers of crate::markdown, which count from zero. The box is Block::bbox as it is: the page as it is displayed, /Rotate applied, in points from the bottom left corner of the crop box with y up (BOTTOMLEFT). pages gives each page’s size in that same frame, which is what makes the box relative to a page and not to a sheet of paper nobody sees.

WHAT HAS NO MAPPING, stated so nobody looks for it:

  • Block::confidence: DoclingDocument has no per-item confidence;
  • Block::spans: Docling items carry no runs, fonts or sizes. The caller that needs them reads crate::to_json;
  • the document’s own list marker: c) and iv. come out as 3. and 4., because the block keeps the number and not the glyphs;
  • title, caption, footnote, picture, formula, code, key-value and form items: the block model has no such kind, so nothing is written under those labels, and pictures, key_value_items and form_items are always empty;
  • origin: the serializer does not see the file, so it is null.

DETERMINISTIC, like the other two serializers: keys in a fixed order, every number through crate::json::number, two spaces per level.

Structs§

DoclingPage
One page of the document as DoclingDocument.pages lists it.

Constants§

DOCLING_CORE_VERSION
The docling-core release whose model defines SCHEMA_VERSION, and the one the round-trip test loads the output with.
SCHEMA_VERSION
The DoclingDocument schema version this writes.

Functions§

to_docling_json
The blocks as a DoclingDocument, pinned to SCHEMA_VERSION.