HTML: an empty <tr> covered by rowspans drops the cells of the next row

Open
#5,585 3 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@chaitanya0305 is already working on this.

Since Nov 25, 2026.

  • #5587 by @chaitanya0305 — open

Assessment

This issue has not been assessed yet.

Description

bug html priority:high

Summary

In the HTML backend, if every cell in a table row has rowspan="2" or more, the next <tr> has no cells of its own. That is valid HTML and common in generated tables. Docling treats the empty row like a header row and does not count it. The rowspans then cover the next real row instead, and its cells are dropped from TableData and from the Markdown and HTML exports. With partial rowspans, cells land in the wrong column instead. The table content is lost without any warning.

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 = {
    "rowspan covers empty tr": '<table><tr><td rowspan="2">a</td><td rowspan="2">b</td></tr><tr></tr><tr><td>c</td><td>d</td></tr></table>',
    "partial rowspan + empty tr": '<table><tr><td rowspan="2">a</td><td>b</td></tr><tr></tr><tr><td>c</td><td>d</td></tr></table>',
    "th rowspan header + empty tr": '<table><tr><th rowspan="2">A</th><th rowspan="2">B</th></tr><tr></tr><tr><td>c</td><td>d</td></tr></table>',
    "uncovered empty tr (control)": "<table><tr><td>a</td><td>b</td></tr><tr></tr><tr><td>c</td><td>d</td></tr></table>",
}
for name, html in CASES.items():
    src = html.encode()
    ind = InputDocument(path_or_stream=BytesIO(src), format=InputFormat.HTML,
                        backend=HTMLDocumentBackend, filename="t.html")
    doc = HTMLDocumentBackend(in_doc=ind, path_or_stream=BytesIO(src)).convert()
    print(name, [[c.text for c in row] for row in doc.tables[0].data.grid])

Actual

rowspan covers empty tr [['a', 'b'], ['a', 'b']]
partial rowspan + empty tr [['a', 'b'], ['a', 'c']]
th rowspan header + empty tr [['A', 'B']]
uncovered empty tr (control) [['a', 'b'], ['c', 'd']]

Expected

rowspan covers empty tr [['a', 'b'], ['a', 'b'], ['c', 'd']]
partial rowspan + empty tr [['a', 'b'], ['a', ''], ['c', 'd']]
th rowspan header + empty tr [['A', 'B'], ['c', 'd']]   (data row kept)
uncovered empty tr (control) [['a', 'b'], ['c', 'd']]              (unchanged)

Cause

In docling/backend/html_backend.py, both parse_table_data and get_html_table_row_col start each row with row_header = True and set it to False only when they see a non-th cell. A <tr> with no cells keeps row_header = True, so it is handled like an all-th rowspan header row and is not counted. The following row is then placed on the row that the rowspans already fill.

Proposed fix

Count a cell-less <tr> as a table row only when an earlier rowspan covers it, as the HTML table model does. An empty row that nothing covers is still skipped, so no blank rows are added (leading, middle and trailing empty rows give the same output as now). There are two regression tests in tests/test_backend_html.py: one for the covered case and one that checks that uncovered empty rows add nothing. No groundtruth file in tests/data has an empty <tr>.

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-empty-table-row. 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.