feat: a cell keeps its own margins where they differ from the table's
w:tcMar and an ODF cell style's own fo:padding were both dropped: the table's value (in ODF the first cell's) stood for every cell. cellPadding is now an attr on tableCell/tableHeader too, measured against the table's rather than the editor default, so only a real disagreement carries one. --cell-pad inherits, so the cell's own declaration wins for its own td and the CSS is unchanged. Checked against LibreOffice: a 1.2cm cell in a 0.3cm table puts its text at 332.2pt where the grid column starts at 297.6.
This commit is contained in:
1 parent
aad4e7a3e4
commit
ca3767f3d4
8 files changed
+81
-36
No files matched your search
@@ -828,9 +828,14 @@ function tableToDocx(node: TiptapNode, contentWidthCm: number, num: Numbering):
|
||||
const fill = typeof bg === 'string' ? hexColor(bg) : undefined;
|
||||
const widthTwip = colsTwip ? colsTwip.slice(col, col + colspan).reduce((a, b) => a + b, 0) : undefined;
|
||||
col += colspan;
|
||||
// The cell's own margins (w:tcMar); absent, Word falls back to the table's.
|
||||
const ownPad = parseCellPadding(cell.attrs?.cellPadding);
|
||||
cells.push(new TableCell({
|
||||
columnSpan: colspan > 1 ? colspan : undefined,
|
||||
rowSpan: rowspan > 1 ? rowspan : undefined,
|
||||
margins: ownPad
|
||||
? { marginUnitType: WidthType.DXA, top: cmToTwip(ownPad[0]), right: cmToTwip(ownPad[1]), bottom: cmToTwip(ownPad[2]), left: cmToTwip(ownPad[3]) }
|
||||
: undefined,
|
||||
shading: fill ? { type: ShadingType.CLEAR, fill } : undefined,
|
||||
width: widthTwip ? { size: widthTwip, type: WidthType.DXA } : undefined,
|
||||
borders: {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type TableStyleRef = { name: string; look: TableLook };
|
||||
import { HEADER_SHADE } from '../editor/extensions/tableHeaderRow';
|
||||
import { BORDER_SIDES, parseBorderAttr } from '../editor/extensions/tableCellBorders';
|
||||
import { parseCellPadding, DEFAULT_CELL_PADDING } from '../editor/extensions/tableCellPadding';
|
||||
import { parseCellPadding, DEFAULT_CELL_PADDING, type CellPadding } from '../editor/extensions/tableCellPadding';
|
||||
import { TEXTBOX_PADDING_CM } from '../editor/extensions/textBox';
|
||||
import { normalizeLeader, parseTabStops } from '../editor/extensions/tabStops';
|
||||
import { charStyleProps, listMarkerFormat, type MarkerFormat } from '../editor/extensions/listMarker';
|
||||
@@ -2523,9 +2523,11 @@ function exportTable(node: TiptapNode, doc: OdtDocument, contentWidthCm: number,
|
||||
const look = parseTableLook(node.attrs?.tableLook);
|
||||
tableStyleNames.push(tableStyle && styleName ? { name: styleName, look } : null);
|
||||
const columnWidths = tableColumnWidthsCm(node, contentWidthCm - (margins ? margins.ml + margins.mr : 0));
|
||||
// The table's cell margins ride on every cell as a TRBL shorthand; expandCellPadding
|
||||
// splits it, since odf-kit only writes fo:padding and ODF only allows one length.
|
||||
const cellPad = (parseCellPadding(node.attrs?.cellPadding) ?? DEFAULT_CELL_PADDING).map(n => `${n}cm`).join(' ');
|
||||
// Cell margins ride on every cell as a TRBL shorthand (ODF has no table-level one);
|
||||
// expandCellPadding splits it, since odf-kit only writes fo:padding and ODF only
|
||||
// allows one length there. A cell's own attr overrides the table's.
|
||||
const tablePad = parseCellPadding(node.attrs?.cellPadding) ?? DEFAULT_CELL_PADDING;
|
||||
const padValue = (p: CellPadding) => p.map(n => `${n}cm`).join(' ');
|
||||
doc.addTable((t: TableBuilder) => {
|
||||
for (const row of rows) {
|
||||
t.addRow((r: RowBuilder) => {
|
||||
@@ -2534,7 +2536,7 @@ function exportTable(node: TiptapNode, doc: OdtDocument, contentWidthCm: number,
|
||||
// Emit the cell's runs (SEG-separated) and record its descriptor; addCell is
|
||||
// synchronous, so the push stays in document order, matching applyCellBlocks'
|
||||
// walk. Spans make odf-kit emit covered cells, which its cell regex never matches.
|
||||
const opts: CellOptions = { padding: cellPad };
|
||||
const opts: CellOptions = { padding: padValue(parseCellPadding(cell.attrs?.cellPadding) ?? tablePad) };
|
||||
const colspan = (cell.attrs?.colspan as number) ?? 1;
|
||||
const rowspan = (cell.attrs?.rowspan as number) ?? 1;
|
||||
if (colspan > 1) opts.colSpan = colspan;
|
||||
|
||||
Reference in new issue
Block a user