docling-project / docling-project/docling-core
DocLangDocSerializer emits an InlineGroup's runs with no enclosing element when the parent TextItem has text of its own
- Dominant language
- HTML
- Stars
- 282
- Forks
- 214
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 23
Description
`DocLangInlineSerializer.serialize` sets `should_wrap = False` for every `InlineGroup` whose parent is a `TextItem`, on the assumption the parent will render the runs as its own element content. `DocLangTextSerializer.serialize` only does that under `if item.children and not item.text:` — so when the parent carries text, the runs are emitted bare at the parent's sibling level. In a `` (or at the `` root) that is invalid against the real DocLang 0.7 XSD, whose `group` content model is `element_head` + `top_level_cat*` and is not `mixed`: `Element 'bold': This element is not expected.` The XML stays well-formed, so `DocLangDocSerializer` does not raise, but `_walk_children` dispatches only on `isinstance(node, Element)`, so the DOM text node between two formatting runs is never visited and the text is silently lost — a content-loss bug independent of the schema one.
Minimal repro (docling-core 2.94.1, doclang 0.7.3): a `DoclingDocument` with a `SectionHeaderItem` that has text, one `InlineGroup` child, and three `TextItem` runs under it (bold, plain, italic). This is the shape docling's own DOCX backend produces for any Word paragraph of inline-formatted runs that follows a heading.
Two candidate fixes: narrow `should_wrap` to `isinstance(parent_item, TextItem) and not parent_item.text`, or have the text serializer render an `InlineGroup` child inside its own element even when it has text of its own.
---
Found while auditing a downstream project's DocLang export pipeline; happy to share the exact synthetic `DoclingDocument` construction used to reproduce this if useful.
Contributor guide
Research direction
Start with DocLangInlineSerializer.serialize and DocLangTextSerializer.serialize, then trace _walk_children for how text nodes and InlineGroup elements are handled. Reproduce the SectionHeaderItem shape described in the issue and verify that the resulting DocLang XML validates against the 0.7 XSD while preserving the parent text and all inline runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100