docling icon indicating copy to clipboard operation
docling copied to clipboard

HTML backend: content of a <details> in a table cell is exported again after the table

Open shlokbam opened this issue 1 week ago • 1 comments

Bug

When a table cell holds a <details> element, its content is not kept inside the cell. The summary and body end up under the document body, so they are exported a second time right after the table. In the DoclingDocument the cell is a plain TableCell with flattened text, and the <details> group is a sibling of the table instead of part of the cell.

When the details body is not a <p> (for example a heading or a <div>), the flattened cell text also runs the words together: <summary>Show example</summary><h5>Run it twice</h5> gives the cell text Show exampleRun it twice.

Expected: the <details> content stays in its cell (as a RichTableCell, like other block content in cells) and appears once in the output.

Steps to reproduce

from io import BytesIO
from docling.datamodel.base_models import DocumentStream
from docling.document_converter import DocumentConverter

html = b"""<html><body><h1>Options</h1>
<table>
  <tr><th>Option</th><th>Notes</th></tr>
  <tr><td>retry</td><td><details><summary>Show example</summary><p>retry=3 waits 2s between tries</p></details></td></tr>
</table>
<p>See also the FAQ.</p>
</body></html>"""
doc = DocumentConverter().convert(DocumentStream(name="options.html", stream=BytesIO(html))).document
print(doc.export_to_markdown())

Output on main (311b683):

# Options

| Option   | Notes                                       |
|----------|---------------------------------------------|
| retry    | Show example retry=3 waits 2s between tries |

Show example

retry=3 waits 2s between tries

See also the FAQ.

The details text appears twice. Collapsible examples in option and API tables are common in docs pages and in HTML rendered from Markdown, so the duplicate text also ends up in chunks.

Cause: _handle_block handles details with self._walk(tag, doc) inside _use_details, but it does not return the group it creates. A table cell collects the refs returned by walking the cell to build its rich content, so it never receives the details group, which stays under the body.

Docling version

main at 311b683 (2.152.0)

Python version

Python 3.12

shlokbam avatar Nov 23 '26 16:11 shlokbam

Classification labels added: bug, priority:medium, html.

These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.

github-actions[bot] avatar Nov 23 '26 16:11 github-actions[bot]