Skip to content

Fix GFM table column cardinality - #717

Open
gaoflow wants to merge 1 commit into
trentm:masterfrom
gaoflow:fix-gfm-table-column-cardinality
Open

Fix GFM table column cardinality#717
gaoflow wants to merge 1 commit into
trentm:masterfrom
gaoflow:fix-gfm-table-column-cardinality

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The tables extra currently uses each source row's own cell count. As a result, it
recognizes mismatched header/delimiter rows and emits short or over-wide body rows,
contrary to GFM's table rules.

This introduces shared row splitting, validates the delimiter width, and normalizes
body rows to the header width. The regression fixture covers both mismatch directions,
missing and excess cells, alignment, and multiple outer-pipe forms; make test and
make testredos pass.

@nicholasserra

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Is there a quick before > after you can show to help me understand what's being fixed here? Thank you

@gaoflow

gaoflow commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Sure — three inputs, all with extras=['tables'], showing only the part of the output that changes.

Body row shorter than the header:

| name | quantity | notes |
| --- | ---: | :--- |
| apples | 3 |

master emits three <th> but only two <td>, so the table comes out ragged; with the PR a third <td style="text-align:left;"></td> is padded in.

Body row longer than the header:

item | state
--- | :---:
pear | ripe | ignored

master emits <td>ignored</td> as a third cell that has no <th> above it; with the PR the extra cell is dropped.

Header and delimiter rows of different widths:

| a | b | c |
| --- | --- |
| d | e |

master renders it as a table anyway; with the PR it is not a table and comes out as <p>| a | b | c |…</p>.

I ran the same three inputs through cmarkgfm and all three of the "after" results match it. test/test.py on top of current master: 273 tests, the same 14 [knownfailure] entries as master, nothing new.

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.

2 participants