fix: paragraph spacing default

This commit is contained in:
Steffen Becker committed 2026-06-25 17:19:17 +02:00
1 parent f4093e24cf
commit 86083e0556
2 files changed
+9 -4

No files matched your search

+7 -4
View File
@@ -347,10 +347,13 @@ function blockAttrs(paraProps: PropMap, textProps: PropMap, headingLevel: number
const defTop = hdef ? hdef.marginTopPt : 0;
const defBottom = hdef ? hdef.marginBottomPt : kind === 'list' ? 0 : STD_MARGIN_BOTTOM_PT;
const mt = lengthToPt(paraProps['fo:margin-top']);
const mb = lengthToPt(paraProps['fo:margin-bottom']);
if (mt != null && Math.abs(mt - defTop) > EPS_PT) attrs.spaceBefore = snapPt(mt);
if (mb != null && Math.abs(mb - defBottom) > EPS_PT) attrs.spaceAfter = snapPt(mb);
// An unspecified fo:margin is ODF's default of 0 (not the editor's 6pt body
// default), so a foreign paragraph that omits it gets 0 spacing like
// Word/LibreOffice. Editor exports write the margins explicitly, so suppressed.
const mt = lengthToPt(paraProps['fo:margin-top']) ?? 0;
const mb = lengthToPt(paraProps['fo:margin-bottom']) ?? 0;
if (Math.abs(mt - defTop) > EPS_PT) attrs.spaceBefore = snapPt(mt);
if (Math.abs(mb - defBottom) > EPS_PT) attrs.spaceAfter = snapPt(mb);
// Left indent → fo:margin-left (cm). Skip lists: their indent lives in the
// list-style level properties, not paraProps. Default 0 is suppressed.
+2
View File
@@ -301,6 +301,8 @@ describe('Leg 2: foreign (LibreOffice/Word-style) .odt → importOdt', () => {
check('foreign: Letter stays portrait', f.orientation === 'portrait');
check('foreign: plain run has no marks', c[0].content![0].marks === undefined, c[0]);
// Omitted fo:margin-bottom → ODF default 0, not the editor's 6pt body default.
check('foreign: omitted margin → spaceAfter 0', c[0].attrs?.spaceAfter === 0, c[0].attrs);
const p1 = c[1];
check('foreign: P1 align end → right', p1.attrs?.textAlign === 'right', p1.attrs);