Files
edentext/tests/unit/marker-align.test.ts
Steffen Becker 3154a9b7a2 feat: a list label takes the alignment the file gives it
Word's w:lvlJc / ODF's fo:text-align on the level: set right, the label grows
into the margin instead of over the text it labels. That is what the built-in
Roman numberings use, and a fixture's numerals collided without it.
2026-08-08 23:09:58 +00:00

36 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Which end of the hanging indent a list label is set against: Word's w:lvlJc,
// ODF's fo:text-align on the level properties. `right` is what keeps a Roman
// numeral out of the text it labels.
import { describe, it, expect } from 'vitest';
import { buildOdt } from '../../src/lib/export/odt';
import { buildDocx } from '../../src/lib/export/docx';
import { importOdt } from '../../src/lib/import/odt';
import { importDocx } from '../../src/lib/import/docx';
type N = any;
const item = (text: string): N => ({ type: 'listItem', content: [{ type: 'paragraph', content: [{ type: 'text', text }] }] });
const doc = (markerAlign?: string): N => ({
type: 'doc',
content: [{
type: 'orderedList',
attrs: { listStyleType: 'upper-roman', ...(markerAlign ? { markerAlign } : {}) },
content: [item('one'), item('two')],
}],
});
const margins = { top: 2, bottom: 2, left: 2, right: 2 };
const list = (d: N) => d.content.find((n: N) => n.type === 'orderedList');
describe('a list label’s alignment', () => {
it('round-trips through ODF', async () => {
expect(list((await importOdt(await buildOdt(doc('right'), margins, 'portrait'))).content).attrs?.markerAlign).toBe('right');
expect(list((await importOdt(await buildOdt(doc(), margins, 'portrait'))).content).attrs?.markerAlign).toBeUndefined();
});
it('round-trips through DOCX', async () => {
expect(list(importDocx(await buildDocx(doc('right'), margins, 'portrait')).content).attrs?.markerAlign).toBe('right');
expect(list(importDocx(await buildDocx(doc(), margins, 'portrait')).content).attrs?.markerAlign).toBeUndefined();
});
});