Repository navigation
HTML import: table widths, cell colours, spans, borders and layout tables (#1878) - #1893
Conversation
…lls (#1878) An HTML table is now read into a RawTable (its cells' blocks and specs) and laid out when the outermost table ends (import/html_table.rs): colspan and rowspan as gridSpan and vMerge over a slot grid, column widths from the table's and cells' width, cell shading, vAlign and tcMar, and the table's border, cellpadding, cellspacing and align as tblPr. A nested table waits in its cell at a placeholder and is laid out in that cell's width, so a 100% table inside a column fills the column, not the outer table. The Builder holds a stack of tables; RTF keeps its one table and today's even grid. A begun HTML cell is ended by its row's or table's end even when it is empty, so an unclosed spacer cell keeps its width and shading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ented (#1878) newsletter-tables.html is the HTML-email shape: a 100% wrapper, a centred 600px borderless container, a colspan header, 200/400 columns, a nested card with class backgrounds, a rowspan cell and a bordered data table. a_newsletter_table_layout_keeps_widths_spans_and_shading pins its widths, spans, shading, vAlign, nesting and borders; the fixture joins the every-prefix test. CLAUDE.md gains an HTML import tables section; the import bounds table lists the attributes read and the table stack and layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A browser's table model clips a rowspan (and rowspan=0) at the end of its row group, so a thead cell's rowspan=2 never reaches the body. RawTable now records where row groups start (a thead/tbody/tfoot open or close; a bare tr after a closed group is a group of its own) and place() clips at the cell's group. Also rewords the stale presentational() doc comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Merged automatically (auto-merge is on for this checkout): review stopped: round 1 had no Major; all findings fixed; merge rounds: none; whole suite green on bc51f21 (11840 tests: Follow-ups (plan out of scope, all Minor): #1894 — CSS borders on tables and cells; row heights / |
HTML import tables now look like the page: nested tables stay nested, spans, widths, cell colours, vertical alignment, and the table's border/padding/spacing/alignment attributes come through. Layout tables (the HTML-email shape: nested,
border=0) import with no visible borders.Closes #1878
What changed
docxcore/src/import/html_table.rs(new): an HTML table is read as aRawTable(cells with their specs) and laid out when the outermost table ends, so a nested table is laid out top-down in its cell's width (less its stated side margins).colspan/rowspan→gridSpan/vMergeover a browser-style slot grid (a rowspan clipped at its row group;rowspan=0to its group's end); ragged rows padded;MAX_COLUMNSrespected.widthattribute (px,%) and CSSwidthontable/td/th→tblGrid,tblW(dxa / pct / auto) and every cell'stcW. Unknown columns share what is left; over-full widths widen the grid; percentages scale to 100.bgcolor/ CSS background, else its row's, row group's or table's (background: none|transparentclears a part's own fill).valign/vertical-alignon cells, rows and row groups →vAlign(inherited; a cell with none iscenter, the browser default).border=N→tblBorders(outer N px, inside 1 px);border=0/absent → none.cellpadding→tblCellMar(0 writes four zeros), a cell's CSSpadding→tcMar,cellspacing→tblCellSpacing(half the HTML gap, unmeasured against Word),<table align>→jc,<tr align>aligns its cells' text.Builder(import/mod.rs) holds a stack of tables; nesting kept to 8 levels (deeper flattens into the enclosing cell as before). An open empty cell (spacer cells) is kept. RTF's table path is unchanged.Tests
cargo test -p docxcore: 2266 passed, 0 failed;cargo clippy -p docxcore --all-targets -- -D warningsandcargo fmt --allclean.html_tableunit tests;html.rstests for spans, widths, over-full widths, shading fallback, valign, border/cellpadding/cellspacing/align, nesting (incl. past 8 and 300 unclosed), a nested 100% table filling its cell, an unclosed spacer cell, a rowspan ending with its row group, and a DOCX round trip (serialize → load: same grid, spans, vMerge, tcPr/tblPr, nesting).docxcore/tests/fixtures/html/newsletter-tables.htmlwitha_newsletter_table_layout_keeps_widths_spans_and_shading(html_css.rs), and in the every-prefix test.an_omitted_cell_or_row_end_is_implied(its nested case now asserts a nested table, not a flattened cell).Review record
Out of scope (follow-ups filed in #1894): CSS borders on tables/cells, row heights /
colwidths /max-width,<center>/margin:0 autotable centring,thdefault bold, page/body background.🤖 Generated with Claude Code