Import read style:vertical-align but neither exporter wrote it, so a mid-cell callout label jumped to the row's top on every save. odf-kit's CellOptions and docx's TableCell both take it natively; DOCX import maps w:vAlign in as well.
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
// A cell's verticalAlign attr round-trips through DOCX (w:vAlign); the ODF leg
|
|
// (style:vertical-align) rides along in roundtrip.test.ts.
|
|
import { describe, it, expect } from 'vitest';
|
|
import { buildDocx } from '../../src/lib/export/docx';
|
|
import { importDocx } from '../../src/lib/import/docx';
|
|
|
|
type N = any;
|
|
|
|
const cell = (text: string, verticalAlign?: string): N => ({
|
|
type: 'tableCell',
|
|
attrs: { colspan: 1, rowspan: 1, colwidth: [120], ...(verticalAlign ? { verticalAlign } : {}) },
|
|
content: [{ type: 'paragraph', content: [{ type: 'text', text }] }],
|
|
});
|
|
|
|
describe('table cell vertical alignment', () => {
|
|
it('round-trips middle/bottom and leaves top unset', async () => {
|
|
const doc: N = {
|
|
type: 'doc',
|
|
content: [
|
|
{ type: 'paragraph', content: [{ type: 'text', text: 'Before' }] },
|
|
{ type: 'table', content: [
|
|
{ type: 'tableRow', content: [cell('A', 'middle'), cell('B', 'bottom'), cell('C')] },
|
|
] },
|
|
],
|
|
};
|
|
const res = importDocx(await buildDocx(doc, { top: 2, bottom: 2, left: 2, right: 2 }, 'portrait'));
|
|
const cells = (res.content.content!.find((n: N) => n.type === 'table') as N).content[0].content;
|
|
expect(cells.map((c: N) => c.attrs?.verticalAlign ?? null)).toEqual(['middle', 'bottom', null]);
|
|
});
|
|
});
|