fix: preserve table sections and nested-table boundaries

#2

Hierarchical JSON export currently repeats a header inside a tbody as data and drops later body groups or footer rows. A table with an ordinary body row and a tfoot Total row consequently loses its total.

Select headers and data from the same ordered rows belonging to the current table. Apply that ownership rule to span expansion as well, and extract cells directly from each row. This keeps nested table rows and cells from changing the outer table's header count, data records or span bounds. Nested tables continue to be exported separately, and their text remains in the containing cell.

The JSON schema is unchanged. Regression cases exercise postprocess_text with synthetic HTML, including sectioned tables, nested headers and cells, and spanning headers with footer totals. Tests for supplied nested HTML disable automatic header inference to isolate export behavior; this change does not fix the separate normalization behavior when header inference is enabled.

Validation on revision 4035ffb1d8f8bafcdb867dfaf6f7514f101464f9:

  • Unmodified postprocessing suite: 35 passed.
  • The same final test file on original production source: 9 failed, 39 passed.
  • Corrected source: all 48 postprocessing tests passed.
  • Additional review checks covered malformed spans, empty groups, footer order and nested-table ownership.

These tests require Python, Beautiful Soup and pytest only. No model inference was used. This contribution concerns export correctness, with no security or recognition-accuracy claim.

AI assistance: Codex prepared the change, regression tests and recorded validation, with iterative code review.

Signed-off-by: Openforge888 dev@openforge.live
Co-Authored-By: Codex (gpt-6-astra) noreply@openai.com

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment