fix(header): keep a first row whose labels wrap onto a second line

MA
5d ago
+33-3

Summary

resolve_header_rows returned 0 as soon as a first-row label contained a line break, so a Word table whose label wraps onto a second line (a second paragraph or a Shift+Enter break) got an empty header row, with the real labels pushed into the body.

The rule is now:

  • A wrapped label is still treated as data if any of its lines is a number, date or boolean (name | 12<br>13 stays in the body).
  • Otherwise it is accepted, but it abstains from the type vote. The row is promoted only on the votes of its single-line labels.
  • The row-shape fallback (text over text, no type signal) still requires every label to be single-line.

That keeps the false positive mentioned in the issue in the body: Alice | N/A<br>(not measured) over a numeric column has no single-line label voting for it, so nothing changes there.

Fixes #223.

Verification

  • New unit test multiline_label_abstains_and_defers_to_single_line_votes covers the issue table, the Alice | N/A<br>(not measured) row, a wrapped numeric cell and an all-text table with a wrapped label.
  • DOCX files built with python-docx 1.2.0, run through cargo run --example convert:
    • Issue repro with a second paragraph and with an inline break: both now give | Date | Start<br>End | Room | as the header. On main both give an empty header row.
    • The single-line version is unchanged.
    • The Alice table renders the same as on main (empty header, Alice row in the body).
  • cargo test --lib: 287 passed. cargo test --tests: header_collision, robustness and snapshot suites pass, with no snapshot changes.
  • cargo fmt --all -- --check and cargo clippy --all-targets clean.

Summary by cubic

Fixes header row detection for Word tables whose first-row labels wrap onto a second line (second paragraph or Shift+Enter break), so the table keeps a real header instead of an empty one with labels pushed into the body.

  • A wrapped label is treated as data only if any of its lines is a number, date, or boolean; otherwise it stays in the header.
  • Wrapped labels abstain from the type vote, so the row is promoted by its single-line labels alone.
  • The text-over-text fallback still requires all labels to be single-line, keeping rows like Alice | N/A<br>(not measured) over numeric data in the body.

Fixes #223.