Skip to content

Preserve table column alignment across row spans - #316

Open
Aschenbath wants to merge 1 commit into
matthewwithanm:developfrom
Aschenbath:fix/big20-20261123-bde6-markdownify-rowspan
Open

Aschenbath wants to merge 1 commit into
matthewwithanm:developfrom
Aschenbath:fix/big20-20261123-bde6-markdownify-rowspan

Conversation

@Aschenbath

Copy link
Copy Markdown

Cells following a rowspan currently shift into the wrong Markdown columns. Expand the occupied slots to empty cells before conversion, on a copy of the table so caller-owned soup remains reusable. Combined row/column spans, empty rows, nested tables and row-group boundaries are handled while preserving existing cell conversion hooks.

Fixes #121.

Validation: all 108 tests pass on Python 3.12; flake8 passes. Nine new regression cases fail on the unchanged baseline.

@manav4u

manav4u commented Nov 26, 2026

Copy link
Copy Markdown

There is a span-normalization mismatch at 3940be5 that can make cell text disappear when the Markdown is rendered:

from markdownify import markdownify

html = '''<table>
<tr><td rowspan="2" colspan="+2">one</td><td>two</td></tr>
<tr><td>three</td></tr>
</table>'''
print(markdownify(html, table_infer_header=True))

Current output:

| one | two |
| --- | --- |
|  |  | three |

_table_span() accepts +2 through int(), so the next row gets two placeholders. But convert_td() / convert_th() and the header-width calculation still use isdigit(), treating the same colspan as 1. The two-column header means both markdown-it-py's table parser and Pandoc's GFM reader discard the third body cell, including three.

The baseline already has incorrect rowspan alignment, but preserves all three cell texts in this example. colspan=" 2 " has the same new text-loss result; ordinary colspan="2" works. This also reproduces without table_infer_header. Checked on Python 3.10 and 3.14; the existing 108 tests pass on both.

Could the occupancy pass and the cell/header emitters use the same span normalization, with a regression covering a non-digit-only colspan? That would keep their column counts consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add table 'rowspan' support

2 participants