Repository navigation
Description
Problem
Word tables merge cells — a header spanning several columns, a value spanning several rows. Mammoth hands those over correctly (colspan/rowspan) and reports no messages, and merged cells are not among the content markUnconvertedContent marks (it covers equations, charts/diagrams and bare objects only, ui-packages/web/src/formats/docx-unconverted.ts:49-83). The loss happens later, in the converter's own DOM pass: flattenTableCells and promoteHeaderRow (ui-packages/web/src/formats/docx.ts:26-61) fix paragraph wrapping and header promotion but do nothing about spans — promoteHeaderRow even copies the colspan attribute into the <th>. GFM pipe tables have no span syntax, so a colspan="2" header leaves the header row one cell shorter than the body rows.
Verified end to end with the repository's own dependencies on a 3×3 Word table (gridSpan + vMerge):
- Mammoth emits
<td colspan="2">/<td rowspan="2">withmessages: []— nothing to warn with. - After the header promotion + turndown/GFM steps, the markdown is a 2-column header over 3-column body rows; both span attributes are silently gone.
- The shared remark→rehype chain (
ui-packages/web/src/formats/markdown-text.ts:29for the assistant,ui-packages/web/src/components/markdown.tsx:103-109for the reader) truncates every row to the header's column count: the third cell's content (audited) disappears from the hast tree entirely, and the surviving values sit under the wrong headings —Total 120andpendingboth render in the Note column.
So a Word report with merged table cells opens with silently corrupted tables, identically wrong for the reader and for the assistant, with no signal at any layer. The same merged-cell fact is already tracked for the xlsx grid as #170; this is the Word side, with a different failure mode (columns shift and overflow cells vanish, not blank runs).
Proposal
- In the DOM pass in
docx.ts, next toflattenTableCellsandpromoteHeaderRow, expand spanned cells before turndown so every row of a table has the same cell count:colspan: repeat the cell's content into each spanned column, or pad with empty cells;rowspan: insert the cell (or a continuation) into each following row at the same column position.
- The output must parse as an aligned GFM table: no cell dropped by the mdast→hast column-count truncation, no value under a wrong heading.
- If padding is chosen over repetition, mark continuation cells (e.g. ditto marks) rather than leaving blanks a reader reads as empty — pick one behavior and pin it with a test.
- Leave the Mammoth-messages path alone: this is structure Mammoth delivers correctly and the converter flattens wrongly.
Goal
After this, a Word document whose tables merge cells opens with every value under its own column heading, in the reader's table and in the assistant's tab-separated text view alike — no cell content dropped, no column shifted — so "what is the note for South?" is answered from the same table the reader sees.
Verification
grep -qi 'merge' ui-packages/web/src/formats/docx.test.ts
pnpm --filter @gamma-reader/web test
pnpm checkRefs
ui-packages/web/src/formats/docx.ts:26-61, 113-124— the DOM pass and turndown/GFM conversion with no span handlingui-packages/web/src/formats/docx-unconverted.ts:49-83— inline markers cover equations/drawings/objects, not table mergesui-packages/web/src/formats/markdown-text.ts:29andui-packages/web/src/components/markdown.tsx:103-109— reader and assistant share the chain that truncates rows to the header's column count- Show a merged cell as merged — its value stops at the top-left square today, leaving blank runs that reader and assistant both read as empty #170 — merged cells on the xlsx side (value stops at the top-left square); this issue is the Word side, where the fix is to unmerge because GFM has no span syntax
- Tell readers which Word content did not convert, instead of logging it to the browser console #45 — the inline-marker precedent for content Mammoth drops; merged cells arrive intact from Mammoth and are lost in the converter, so they belong in the converter, not the marker
Activity
bencode commentedon Oct 22, 2026
Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire
source:scheduledproposals.Evidence audit (against
main@ebb0ee0): every citation confirmed, most to the exact line.withinTableCell/flattenTableCells/promoteHeaderRowspandocx.ts:26-61, invoked with turndown+gfm at:110-124; neither helper touches spans, andpromoteHeaderRow's attribute loop (for (const attribute of cell.attributes) heading.setAttribute(...)) does copycolspaninto the<th>, as claimed.docx-unconverted.ts:49-83covers equations, charts and bare embedded objects only; no merge/table concept anywhere in it.markdown-text.ts:29(unified().use(remarkParse).use(markdownPlugins).use(remarkRehype)) for the assistant,components/markdown.tsx:103-109(ReactMarkdown over the same plugin family) for the reader. remark-gfm derives table width from the header row and drops overflow cells in mdast→hast, so the 2-column-header/3-column-body corruption follows from the code as cited.Duplicate check: no other open or closed issue touches Word table conversion.
Sensor: lint ✓, verify ✗ → not implemented on main; stays open.
Verdict: valid, keep open. The diagnosis layer is unusually precise (loss located in the converter's DOM pass, not Mammoth), and the fix site sits next to two existing helpers doing the same kind of pre-turndown normalization.
One anchor sharpening before implementation (the #41/#55 lesson):
grep -qi 'merge' docx.test.tsmisses a test suite that speakscolspan/rowspan/span— and the proposal itself floats OOXML vocabulary (gridSpan,vMerge). One pattern covers every vocabulary in play (including "unmerge" and both OOXML terms, case-insensitively):grep -qiE 'merge|span' ui-packages/web/src/formats/docx.test.tsbencode commentedon Oct 24, 2026
Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. (Signal check: marker-only comments, no reactions, no assignee.)
Delta since last review (
ebb0ee0→90b046f): zero commits touchformats/or either markdown render chain — the ~20 commits on main since are all composer/conversation/tab work.90b046f:withinTableCell/flattenTableCells/promoteHeaderRowstill spandocx.ts:26-61with the turndown/GFM invocation at:110-124;markdown-text.ts:29still the sharedremarkParse → markdownPlugins → remarkRehypechain. No span handling added anywhere in the pass.Verdict: still valid, keep open; no action. The prior review's sharpened test anchor (
grep -qiE 'merge|span' ui-packages/web/src/formats/docx.test.ts) remains the right gate — it covers every vocabulary in play (colspan,gridSpan,vMerge, "unmerge").