feat: a table that may not break between rows moves whole
ODF style:may-break-between-rows="false" — probed: LibreOffice leaves four lines of a page empty rather than split such a table, and splits the identical one when the attribute says "true". pageBreaks now emits a single atomic leaf for the wrapper unless the table is taller than a page, where the rule cannot be met. Imported, exported and round-tripped; Word has no equivalent.
This commit is contained in:
1 parent
0d3506a51c
commit
db8f4439b1
7 files changed
+88
-19
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// ODF style:may-break-between-rows="false": the table moves whole rather than break.
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { unzipSync, strFromU8 } from 'fflate';
|
||||
import { buildOdt } from '../../src/lib/export/odt';
|
||||
import { importOdt } from '../../src/lib/import/odt';
|
||||
|
||||
type N = any;
|
||||
|
||||
const cell = (text: string): N => ({
|
||||
type: 'tableCell',
|
||||
content: [{ type: 'paragraph', content: [{ type: 'text', text }] }],
|
||||
});
|
||||
const table = (attrs: N): N => ({
|
||||
type: 'table',
|
||||
attrs,
|
||||
content: [0, 1].map((r) => ({ type: 'tableRow', content: [cell(`a${r}`), cell(`b${r}`)] })),
|
||||
});
|
||||
|
||||
describe('table keep-rows', () => {
|
||||
it('round-trips style:may-break-between-rows', async () => {
|
||||
const doc: N = { type: 'doc', content: [table({ keepRows: true })] };
|
||||
const bytes = await buildOdt(doc, undefined, 'portrait');
|
||||
expect(strFromU8(unzipSync(bytes)['content.xml'])).toContain('style:may-break-between-rows="false"');
|
||||
expect(importOdt(bytes).content.content?.[0]?.attrs?.keepRows).toBe(true);
|
||||
});
|
||||
|
||||
it('leaves a table that may break without the attribute', async () => {
|
||||
const doc: N = { type: 'doc', content: [table({})] };
|
||||
const bytes = await buildOdt(doc, undefined, 'portrait');
|
||||
expect(strFromU8(unzipSync(bytes)['content.xml'])).not.toContain('may-break-between-rows');
|
||||
expect(importOdt(bytes).content.content?.[0]?.attrs?.keepRows ?? null).toBe(null);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user