Commit 93b77bc
fix(serializer): collapse multi-row column headers into one markdown header
MarkdownTableSerializer hardcoded `headers=rows[0]` and `rows[1:]` as the
body. When TableFormer (correctly) marks multiple leading rows as
column_header=True — the case where a column title wraps onto two visual
lines like "Cash per Security" + "($)" — only the first row rendered as
the markdown header and the continuation leaked into the body as a
spurious "data" row.
Mirrors the logic that already exists in
`_export_to_dataframe_with_options` (document.py:2219-2245): count leading
grid rows containing any column_header cell, concatenate their cell text
per column to build the markdown header, and use the remaining grid rows
as the body. Spanning siblings render empty in both cases so a colspan=N
header is not concatenated N times.
Falls back to "first row is header" if no row has any column_header cell,
preserving prior behaviour for tables that arrive without header marking.
Empirical result on a 10-PDF dividend-statement corpus
(finance_nexus tests/fixtures/dividend_statement/):
* IOZ_Reinvestment_Plan_Advice_2025_04_17.pdf: the wrapped header
collapses from two rows into one. Body unchanged.
* All 9 other fixtures: byte-identical markdown output.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 275bd1d commit 93b77bc
1 file changed
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
552 | 588 | | |
553 | 589 | | |
554 | 590 | | |
555 | | - | |
556 | | - | |
| 591 | + | |
557 | 592 | | |
558 | | - | |
| 593 | + | |
559 | 594 | | |
560 | 595 | | |
561 | 596 | | |
562 | | - | |
563 | | - | |
| 597 | + | |
| 598 | + | |
564 | 599 | | |
565 | 600 | | |
566 | 601 | | |
| |||
0 commit comments