Expand description
docling-core’s inline whitespace contract (schema 1.11.0, docling-core#693, docling#3891).
The runs of an inline group carry their own boundary whitespace, and the
Markdown, HTML and LaTeX serializers concatenate them as they are. Before
the contract every serializer joined runs with a hard " ", inventing
spaces the source never had — 2nd → 2 nd, H₂O. → H 2 O .,
**bold** . — which no backend could undo while the separator lived in the
serializer. Three helpers carry the contract:
hoist— docling-core’spost_processwithhoist_decoration_whitespace: a run’s edge whitespace goes outside its whole decoration stack (formatting and hyperlink together), so"bold "renders**bold**and never**bold **, which CommonMark prints as literal asterisks; a whitespace-only run is returned verbatim, undecorated and unlinked.trim_run_edges— docling’strim_run_edges(docling/utils/_inline_runs.py): a backend that keeps each run’s whitespace trims only the block’s outer edges.separate_legacy_runs— docling-core’s_migrate_legacy_inline_separators: the old" "join re-injected into the runs themselves, for a document stamped below 1.11.0 and for an item tree whose backend still builds trimmed runs (crate::tree::ItemTree::inline_whitespaceunset), so their visible output — extra-space bugs included — is what it was.
Structs§
- Legacy
Run - One child of an inline group, as
separate_legacy_runssees it.
Functions§
- hoist
- docling-core’s
post_processunderhoist_decoration_whitespace: decorate the run’s core and keep its edge whitespace outside the markers. A whitespace-only (or empty) run comes back verbatim — no markers, no empty hyperlink. - is_
blank - Whether
textis empty or whitespace only. - is_
space - Python’s
str.isspaceset, which docling-core’sstrip()removes: UnicodeWhite_Spaceplus the ASCII information separators U+001C–U+001F. - migrate_
legacy_ json - docling-core’s
_migrate_legacy_inline_separatorson a docling-JSON document: when itsversionpredates 1.11.0, everyinlinegroup’s runs get the" "the old join put between them (separate_legacy_runs), a standalone separator run appended totexts(with the left run’s location,charspan[0, 1], when both runs share a page) where both neighbours are delimited. Returns whether anything changed. Onlytextmoves;origkeeps what the producer wrote. - predates_
contract - Whether a docling-JSON
versionpredates the inline whitespace contract (below 1.11.0). An unparsable or missing version is not migrated — docling-core leaves versionless input alone rather than guess. - separate_
legacy_ runs - docling-core’s
_migrate_legacy_inline_separators, for one inline group: one" "at every boundary the old serializer joined. Between two consecutive runs that render text the left run takes a trailing space when it is a plain run with text, else the right one a leading space, else an empty plain run between them is refilled, else — both neighbours code or formula runs, where a space would land inside`/$— a standalone" "run is needed. Returns the child positions such runs go in front of, in ascending order (the caller inserts them, shifting as it goes). - split_
edges textsplit into its leading whitespace, its core and its trailing whitespace (Python’slstrip/strip/rstripboundaries). A whitespace-only text is all lead.- trim_
run_ edges - docling’s
trim_run_edges: drop the whitespace-only runs at either edge of a block, strip the outer whitespace of the first and last remaining run, keep every interior run as it is, and drop trimmable runs left without text. A runtrimmablerefuses (a line break, an image) stops the trim at its edge and is always kept.