markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

HTML tables lose the header delimiter row after `<caption>` or `<colgroup>`, and `<tfoot>` adds a fake header

Open Om-singhaI opened this issue 2 months ago • 2 comments

When a table's rows sit directly under <table> (not in <thead> or <tbody>), a <caption> or <colgroup> before them drops the | --- | line under the header. Without it the output isn't a Markdown table anymore, just lines of pipes. JDK 8 and 11 Javadoc summary tables are built this way.

A <tfoot> row has the opposite problem. It gets its own empty header and | --- | line in the middle of the table.

Repro on main (945314a, markdownify 1.2.3):

from markitdown.converters import HtmlConverter

c = HtmlConverter()
print(c.convert_string(
    "<table><caption>Stock</caption><tr><th>Name</th><th>Qty</th></tr>"
    "<tr><td>Apple</td><td>3</td></tr></table>").markdown)
print(c.convert_string(
    "<table><thead><tr><th>Item</th><th>Cost</th></tr></thead>"
    "<tbody><tr><td>A</td><td>1</td></tr></tbody>"
    "<tfoot><tr><td>Total</td><td>1</td></tr></tfoot></table>").markdown)

What I get:

Stock

| Name | Qty |
| Apple | 3 |
| Item | Cost |
| --- | --- |
| A | 1 |
|  |  |
| --- | --- |
| Total | 1 |

I expected | --- | --- | under the first header, the same as without the caption. The footer should just be the last row, | Total | 1 |.

Om-singhaI avatar Sep 18 '26 16:09 Om-singhaI

Hi maintainers, I'd like to work on issue #2536. I plan to add regression tests for the missing Markdown table header separator after a caption and the extra separator generated by a table footer, then implement a focused fix. Is this issue still available for contribution?

Sanjanabonagiri16 avatar Oct 15 '26 13:10 Sanjanabonagiri16

Ok I have done som analysis on this task and I think its worth commenting, what HTML XSD's does this HTML actually comply with. Javadoc HTML does not make it valid HTML. So before fixing this issue this should be determined as the solution to the problem would likely differ depending on the answer to this question. There would be substantial argument not to implement at all if it did comply with any XSD. IMHO I would take: https://github.com/microsoft/markitdown/pull/2537/changes as starting point (requires a lot more testing but has no side effects on existing functionality) the other 2 PRs represent potentially poor solutions if as I suspect this not actually valid HTML. It is common for lots of system browser for example to tolerate and render invalid HTML so its a judgement call whether this issue is to be fixed.

wendycameronordinix avatar Nov 06 '26 14:11 wendycameronordinix