Skip to main content

Module inline

Module inline 

Source
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’s post_process with hoist_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’s trim_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_whitespace unset), so their visible output — extra-space bugs included — is what it was.

Structs§

LegacyRun
One child of an inline group, as separate_legacy_runs sees it.

Functions§

hoist
docling-core’s post_process under hoist_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 text is empty or whitespace only.
is_space
Python’s str.isspace set, which docling-core’s strip() removes: Unicode White_Space plus the ASCII information separators U+001C–U+001F.
migrate_legacy_json
docling-core’s _migrate_legacy_inline_separators on a docling-JSON document: when its version predates 1.11.0, every inline group’s runs get the " " the old join put between them (separate_legacy_runs), a standalone separator run appended to texts (with the left run’s location, charspan [0, 1], when both runs share a page) where both neighbours are delimited. Returns whether anything changed. Only text moves; orig keeps what the producer wrote.
predates_contract
Whether a docling-JSON version predates 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
text split into its leading whitespace, its core and its trailing whitespace (Python’s lstrip / strip / rstrip boundaries). 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 run trimmable refuses (a line break, an image) stops the trim at its edge and is always kept.