HTML: an empty <tr> covered by rowspans drops the cells of the next row
Maintainers usually reply within 2 days
Assessment
This issue has not been assessed yet.
Description
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
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from docling-project/docling
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
docling-project/docling#5592 ·
Maintainers usually reply within 2 days
-
`api_image_request` logs and propagates the raw error response body, leaking the request's API key on 401Possibly taken @prassu017 claimed this 7 days ago. Openbug priority:critical
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
docling-project/docling#5486 · 1 comment · 1 reaction ·
Maintainers usually reply within 2 days
-
AFP: export_to_doctags() raises ZeroDivisionError because every page has size 0x0Possibly taken @Krushil-Dhankecha claimed this 12 days ago. Openbug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
docling-project/docling#5355 · 1 comment ·
Maintainers usually reply within 2 days
-
AsciiDoc: thematic breaks and page breaks are kept as text or turned into list itemsPossibly taken @sohailshk claimed this 12 days ago. Openasciidoc bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
docling-project/docling#5331 · 1 comment ·
Maintainers usually reply within 2 days
-
Merged paragraph across pages of different heights: continuation bbox uses the first page's heightPossibly taken @galer1us claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docling-project/docling#5286 ·
Maintainers usually reply within 2 days
All issues in docling-project/docling
Similar issues
-
Task select patterns with uppercase letters never matchPossibly taken @manobhisriram claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
app: scripts status: backlog type: housekeeping
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
netbox-community/netbox-scripts#239 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
developmentseed/titiler-cmr#341 ·
Maintainers usually reply within 1 day
-
Card tables add "..." to every value in a DataFrame column when any value is longer than 30 charactersPossibly taken @omkarbandikatte claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day