Skip to content

fix(render): unwrap single-cell tables that wrap a nested table - #17

Open
mathurshubham wants to merge 1 commit into
firecrawl:mainfrom
mathurshubham:fix/unwrap-single-cell-table-wrappers
Open

fix(render): unwrap single-cell tables that wrap a nested table #17
mathurshubham wants to merge 1 commit into
firecrawl:mainfrom
mathurshubham:fix/unwrap-single-cell-table-wrappers

Conversation

@mathurshubham

@mathurshubham mathurshubham commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #14.

This implements direction (3) from the issue — the narrow single-cell-wrapper
case — since it covers the reported form shape without touching genuine
nested grids or costing the clean-Markdown property.

What

A nested table inside a cell flattens to a / b runs. For real multi-cell
grids that's unavoidable in GFM, but when the outer table is a single
cell
it is pure layout scaffolding (the Word-form shape: one wrapper table
around the actual content), and flattening collapses the inner grid into one
enormous cell for no benefit.

The renderer already unwraps trivial Layout-kind single-cell tables
(render/markdown/mod.rs); no frontend currently produces Layout, so the
mechanism sat unused. This PR extends that arm: a single-cell table whose
lone cell holds a nested table unwraps to its blocks regardless of kind,
letting the inner table render as a real grid.

Deliberately unchanged:

  • plain | x | 1×1 data tables stay tables (existing
    data_table_1x1_not_unwrapped test still passes untouched);
  • a nested table inside a multi-cell grid keeps today's flatten (new test
    pins it) — that's option (1)/(2) territory and out of scope here.

Wrapper-in-wrapper unnests recursively, so multi-level form scaffolding
resolves too.

Before / after

The issue's repro (3×2 table inside a single-cell outer table), reproduced
byte-for-byte on main and converted with this branch:

-|  |
-| --- |
-| Section A<br>Metric / Value<br>Height / 120<br>Weight / 34<br>End of section |
+Section A
+
+|  |  |
+| --- | --- |
+| Metric | Value |
+| Height | 120 |
+| Weight | 34 |
+
+End of section

Because the fix lives in the renderer, it applies to every format that can
produce nested tables (docx, rtf, epub/html), not just docx.

Tests

  • Renderer unit tests: wrapper around a nested table unwraps (the repro
    shape); nested table in a multi-cell grid still flattens; wrappers unwrap
    recursively; plain 1×1 data table unchanged.
  • New handmade fixture handmade-nested.docx (single-cell wrapper with a
    nested 3×2 table, plus a two-cell table with a nested table to pin the
    flatten path) + its snapshot.
  • cargo fmt --check, clippy --workspace --all-targets --all-features -D warnings, cargo test --locked all green; no existing snapshot
    changed
    — the only snapshot in the diff is the new fixture's.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

A nested table inside a cell flattens to `a / b` runs — unavoidable in
GFM for real multi-cell grids, but when the outer table is a single
cell it is pure layout scaffolding (the Word-form shape: one wrapper
table around the actual content). Flattening there collapses the inner
grid into one enormous cell for no benefit.

Extend the existing trivial-layout-table unwrap in the renderer: a
single-cell table whose lone cell holds a nested table now renders its
content directly, letting the inner table render as a real grid.
Multi-cell tables and plain 1x1 data tables are unchanged.

Fixes firecrawl#14
@mathurshubham
mathurshubham force-pushed the fix/unwrap-single-cell-table-wrappers branch from d1041b5 to 35f278e Compare August 6, 2026 08:41
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.

Nested tables are flattened into a single cell, losing the inner grid

1 participant