HTML: lists, tables and images inside <dt> are dropped
Summary
The HTML backend drops all block content inside a description term (<dt>): lists, tables, images and nested <dl>. HTML allows flow content in <dt>, and pages use it for logo glossaries, spec sheets with a small table in the term, and FAQ markup.
The text of the term skips these blocks on purpose, but unlike the <dd> and <li> paths, no other step then adds them to the document. A term that holds only an image disappears completely, and its <dd> becomes a top-level item with no term. Nothing is logged.
Reproduction
Run on current main (0521b433):
from io import BytesIO
from docling.backend.html_backend import HTMLDocumentBackend
from docling.datamodel.base_models import InputFormat
from docling.datamodel.document import InputDocument
CASES = {
"dt_with_list": b"<dl><dt>Colors<ol><li>red</li><li>blue</li></ol></dt><dd>palette</dd></dl>",
"dt_with_table": b"<dl><dt>Sizes<table><tr><td>S</td><td>M</td></tr></table></dt><dd>shirts</dd></dl>",
"dt_image_only": b'<dl><dt><img src="a.png" alt="ACME logo"></dt><dd>ACME Corp</dd></dl>',
"dd_with_list_control": b"<dl><dt>T</dt><dd>D<ul><li>nested</li></ul></dd></dl>",
}
for name, src in CASES.items():
in_doc = InputDocument(path_or_stream=BytesIO(src), format=InputFormat.HTML,
backend=HTMLDocumentBackend, filename="t.html")
doc = HTMLDocumentBackend(in_doc=in_doc, path_or_stream=BytesIO(src)).convert()
print(name, [t.text for t in doc.texts], "tables:", len(doc.tables), "pictures:", len(doc.pictures))
Actual
dt_with_list ['Colors', 'palette'] tables: 0 pictures: 0
dt_with_table ['Sizes', 'shirts'] tables: 0 pictures: 0
dt_image_only ['ACME Corp'] tables: 0 pictures: 0
dd_with_list_control ['T', 'D', 'nested'] tables: 0 pictures: 0
Expected
dt_with_list:redandblueare kept, nested under the termColors.dt_with_table: one table.dt_image_only: one picture under a term item, withACME Corpnested under that term.dd_with_list_control: unchanged (the<dd>path already works).
Cause
In docling/backend/html_backend.py, the <dt> branch adds the term with _add_list_item_with_content. That helper leaves nested lists, tables and images out of the term text. The <dd> branch then calls _process_list_item_nested_content for those blocks, but the <dt> branch does not, so they are never added.
Proposed fix
After the term item is created, process the nested content of the <dt> the same way as for <dd>. When the term has no text but holds an image, table or list, create an empty term item to hold it, as the <li> path already does. The change is +14 lines in html_backend.py plus a regression test in tests/test_backend_html.py. The groundtruth for tests/data/html/html_description_list.html does not change.
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/docling/compare/main...chaitanya0305:docling:fix/html-dt-nested-content. If this is accepted, I'll open the PR straight away.
Classification labels added: bug, priority:medium, html.
These labels are advisory. Maintainers can correct them. The workflow preserves these corrections.
I can reproduce this on 17285a8 (current main): lists, tables and images inside <dt> are dropped, while the <dd> path keeps nested content. I'll work on a fix with regression tests.
Thanks for confirming the repro on current main! I already have a fix with regression tests for this (branch fix/html-dt-nested-content) and will open the PR once a maintainer gives the go-ahead, so please hold off to avoid duplicate work.