HTML: lists, tables and images inside <dt> are dropped

Open
#5,586 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@rome-xi is already working on this.

Since Nov 26, 2026.

  • #5614 by @rome-xi — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
24/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start in docling/backend/html_backend.py at the dt and dd handling branches, then compare how nested content is processed for dd and li. Add regression coverage in tests/test_backend_html.py for terms containing lists, tables, and images, including an image-only term. Done means those contents are preserved under the term and the existing dd behavior remains unchanged; the issue says the groundtruth does not need updating. A tested fix is already linked, so check with the maintainers before starting overlapping work.

Written by the indexing model from the issue text.

Description

bug html priority:medium

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: red and blue are kept, nested under the term Colors.
  • dt_with_table: one table.
  • dt_image_only: one picture under a term item, with ACME Corp nested 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.

Dominant language
Python
Stars
71k
Forks
5.4k
Avg merge
2d 22h
Merged PRs (30d)
161

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docling-project/docling

All issues in docling-project/docling

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.