diff --git a/src/lib/export/docx.ts b/src/lib/export/docx.ts index 2b29817..e036485 100644 --- a/src/lib/export/docx.ts +++ b/src/lib/export/docx.ts @@ -2312,10 +2312,17 @@ function characterStyleOf(style: Style): ICharacterStyleOptions { return { id: docxStyleId(style.name), name: style.name, quickFormat: true, run }; } +// fromXmlString returns a nameless wrapper around the parsed root that would serialize +// as a literal element — LibreOffice skips it, Word rejects the whole part. +function styleXmlComponent(xml: string): ImportedXmlComponent { + const wrapped = ImportedXmlComponent.fromXmlString(xml); + return (wrapped as unknown as { root: ImportedXmlComponent[] }).root[0]; +} + // Word needs a referenced table style to exist. ODF/our model hold the banding, and the // look is baked into the cells, so a name-only definition is enough (no w:tblStylePr). function tableStyleXml(name: string): ImportedXmlComponent { - return ImportedXmlComponent.fromXmlString( + return styleXmlComponent( `` + `` + '', @@ -2337,7 +2344,7 @@ function usedTableStyles(doc: TiptapNode, sheet: StyleSheet): string[] { // Word needs a referenced numbering style to exist; its w:numId placeholder (0) is // rewritten by applyListStylesDocx once the packed numbering ids are known. function numberingStyleXml(name: string): ImportedXmlComponent { - return ImportedXmlComponent.fromXmlString( + return styleXmlComponent( `` + `` + '' diff --git a/tests/docx-roundtrip.test.ts b/tests/docx-roundtrip.test.ts index bd7e477..2fba343 100644 --- a/tests/docx-roundtrip.test.ts +++ b/tests/docx-roundtrip.test.ts @@ -150,6 +150,7 @@ describe('DOCX export → import round trip', () => { const stylesXml = strFromU8(files['word/styles.xml']); expect(xml).toContain(' { expect(style).toContain(''); expect(//.test(style), 'placeholder numId resolved').toBe(true); expect(styles).toContain('w:styleId="DiamondBullets"'); + // fromXmlString's nameless wrapper would serialize as — Word refuses that. + expect(styles).not.toContain(' {