docling-project / docling-project/docling-core

Serialization of inline groups adds extra spaces before and after group items

Open
#371 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
HTML
Stars
282
Forks
214
Avg merge
2d 16h
Merged PRs (30d)
23

Description

This issue shows gaps in the serialization of inline groups:

- Inline groups within rich table cells get serialized with a new paragraph (in HTML) for each group item. For instance, check the serialization of the test `docx` file [docx_rich_cells.docx](https://github.com/docling-project/docling/blob/main/tests/data/docx/docx_rich_cells.docx) to HTML.
- The serializations of inline groups add a blank space before and after every item of the group.
Even though some applications may deal with double blank spaces, the presentation of the text may be altered and eventually introduce new tokens. This is the case of inline groups created for addressing formatted text.

For instance, consider the text:

```text
Docling supports bold, italic, strikethrough, underline, and formulas like H20.
```

with some applied formatting as in the following `DoclingDocument` created programmatically:

```python
from docling_core.types.doc import DoclingDocument
from docling_core.types.doc.document import Formatting
from docling_core.types.doc.labels import DocItemLabel

doc = DoclingDocument(name="Test")
inline = doc.add_inline_group(parent=None)
doc.add_text(label=DocItemLabel.TEXT, text="Docling supports ", parent=inline)
doc.add_text(label=DocItemLabel.TEXT, text="italic", parent=inline, formatting=Formatting(italic=True))
doc.add_text(label=DocItemLabel.TEXT, text=", ", parent=inline)
doc.add_text(label=DocItemLabel.TEXT, text="strikethrough", parent=inline, formatting=Formatting(strikethrough=True))
doc.add_text(label=DocItemLabel.TEXT, text=", ", parent=inline)
doc.add_text(label=DocItemLabel.TEXT, text="underline", parent=inline, formatting=Formatting(underline=True))
doc.add_text(label=DocItemLabel.TEXT, text=", subscripts like H", parent=inline)
doc.add_text(label=DocItemLabel.TEXT, text="2", parent=inline, formatting=Formatting(script="sub"))
doc.add_text(label=DocItemLabel.TEXT, text="0, and ", parent=inline)
doc.add_text(label=DocItemLabel.TEXT, text="bold", parent=inline, formatting=Formatting(bold=True))
doc.add_text(label=DocItemLabel.TEXT, text=".", parent=inline)

doc.export_to_markdown()
doc.export_to_html()
```

The serialization to markdown shows these extra spaces:

```text
Docling supports *italic* , ~~strikethrough~~ , underline , subscripts like H 2 0, and **bold** .
```

Also to HTML:

```html


Docling supports italic , strikethrough , underline , subscripts like H 2 0, and bold .

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the programmatic DoclingDocument example and the tests/data/docx/docx_rich_cells.docx fixture, then trace export_to_markdown() and export_to_html() handling of inline groups. Done means inline group items remain in the correct HTML structure and both serializers preserve the original text without added spaces around formatted items.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.