Files
Anusha AcharyaandCesar Berrospi Ramis 9b23d315af fix(serializer): derive markdown table header rows from column_header flags (#723)
* fix(serializer): derive markdown table header rows from column_header flags

MarkdownTableSerializer hardcoded grid row 0 as the only header row, while
TableItem._export_to_dataframe_with_options, the HTML serializer and the OTSL
export all derive the header rows from TableCell.column_header. A table with a
stacked header therefore serialized to markdown with its lower header rows
demoted to data rows, and HybridChunker repeated only the first of them at the
top of each chunk of an oversized table.

Take the header row count from the flags and flatten those rows into the single
header row GFM allows, dropping the repeated text a cell spanning several header
rows produces. When no cell in the table carries column_header the previous
behavior is kept, since backends that never set the flag cannot be told apart
from genuinely headerless tables.

Signed-off-by: Anusha Acharya <acharyaanusha123@gmail.com>

* test(serializer): cover tables whose header flags start below row 0

The empty-header-block branch of _flatten_header_rows was the one line of the
patch left uncovered. Pin the behavior it produces: with no leading run of
flagged rows there is no header to promote, so the header is empty and every
row stays in the body rather than one being consumed.

Signed-off-by: Anusha Acharya <acharyaanusha123@gmail.com>

* fix(serializer): join stacked header cells with a documented separator

Review feedback: a blank space loses the boundary between header levels, so
"native backend" over "TTS" is indistinguishable from a single cell reading
"native backend TTS". Join with " - " instead, kept as a module constant, and
document the header-resolution contract on MarkdownTableSerializer.

Signed-off-by: Anusha Acharya <acharyaanusha123@gmail.com>

* fix(serializer): only count header rows a column header starts on

TableData.grid repeats a row-spanning cell into every row it covers, so a
header cell with row_span > 1 leaves a column_header-flagged cell in the data
rows beneath it. Counting every row that holds a flagged cell therefore pulled
those data rows into the header block, where they were flattened into the
column names and dropped from the body entirely.

Require that a header cell starts on the row, matching the same fix applied to
the DataFrame export in #756.

Signed-off-by: Anusha Acharya <acharyaanusha123@gmail.com>

* perf(serializer): avoid iterating grid twice; style and tests improvements

In '_count_header_rows' of the Markdown serializer, avoid iterating
the entire grid twice in all scenarios.
Strengthen docstrings in markdown serializer.
Add test for single header row with flags.

Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>

---------

Signed-off-by: Anusha Acharya <acharyaanusha123@gmail.com>
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Co-authored-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
2026-09-10 14:03:23 +02:00
..