Repository navigation
feat(tables): format --cell-margins sets table-default and per-cell padding - #23
Merged
Merged
Conversation
…adding `tables format` could shade, align, border and size cells but not pad them, so a table rebuilt to match a template's 15-twip margins came out visibly different with no fix short of `raw edit`. --cell-margins takes one measure or top,right,bottom,left (units required, 0 allowed, `none` clears). With --at tN it writes the table default <w:tblCellMar> (Word's "Default cell margins", inherited by rows added later); a row/column/cell/range writes each cell's <w:tcMar>, which tracks as a real tcPrChange. The table default rides the audit-comment path like --align/--style. Both read back: Table.cellMargins / TableCell.margins in the AST and `cell-margins=` / `margins=` on the docx:table / docx:cell notes, in the flag's own shape so an agent can re-apply a template's value verbatim. The reader accepts Word's left/right-only form and strict start/end. Folded into the tables-mutations fixture and the invoice weak-agent scenario.
Owner
|
@xsvm taking a look |
…ed units Review follow-ups on --cell-margins: - read hints are deviation-only against what the padding inherits: a table's against its style chain (new Table.styleCellMargins, resolved by StylesView.tableCellMargins: tblStyle -> basedOn, else the default table style only when no style is named — verified in Word), a cell's against the table's effective padding. Restated defaults (LibreOffice's 0,108,0,108) print nothing. - Uniform per-cell padding folds into one table-note cell-margins (mnda: 42 cell hints -> 2 table notes). A whole-table set now also clears cells' own <w:tcMar> so the folded value re-applies (it used to exit 0 with no visible change); under tracking that stays one untracked change + audit comment. - `-` in --cell-margins keeps that side as it is (merged in place, strict start/end preserved); an all-`-` value is a usage error. - --cell-margins and --row-height take the shared unit table (in, ", cm, mm, pt, tw/dxa) via parseUnitMeasure; bare numbers still rejected. - docx styles --at shows a table style's cell-margins. - insert-row copies the neighbor cell's padding along with its borders. - Nested tables get their docx:table note inline in the outer cell. - Invoice weak-agent scenario change reverted: its table already renders 5.4pt padding, so the "tight against the walls" premise was false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kklimuk
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tables formatcan shade, align, border and size cells, but not pad them. Rebuildingtables to match a template that sets
<w:tblCellMar>(15 twips in my case) left themvisibly different, with
raw editas the only fix — andreaddidn't show thetemplate's margins at all, so an agent couldn't tell why.
--cell-margins M | T,R,B,L | none(units required,0allowed)--at tN→ table default<w:tblCellMar>(Word's "Default cell margins"; rows addedlater inherit it). Untracked + audit comment under tracking, like
--align/--style.<w:tcMar>, tracked as a realtcPrChange.Table.cellMargins/TableCell.marginsin the AST,cell-margins=/margins=ondocx:table/docx:cellnotes, printed in the flag's own shape so thevalue can be re-applied verbatim. Reads Word's left/right-only form and strict
start/end.tables-mutationst0 now sets a table default + one cell override.invoicescenario asks for ~4pt left/right padding.Test plan
bun run checkbun run test:unit(6 new cases intests/cli/tables.test.ts)DOCX_LO_ALL=1 bun run test:integration(fork CI, LibreOffice round-trip)readnow flags the margin mismatch; one call per table makesthe rebuilt tables' XML identical to the original's, and
docx validatepasses