fix: only one w:displayBackgroundShape in settings.xml
The docx package always writes the element; the page-background pass prepended a second one, breaking the CT_Settings sequence so Word repairs the file on open — and the repair drops every header and footer reference. The schema test's DOCX leg now builds with the page decor, line numbering and fold marks, which covers the pass.
This commit is contained in:
1 parent
92a2421a83
commit
43903319d9
2 files changed
+10
-5
No files matched your search
@@ -1660,11 +1660,15 @@ function applyPageDecorDocx(bytes: Uint8Array, decor: PageDecor, widthPt: number
|
||||
const color = decor.background.replace('#', '').toUpperCase();
|
||||
doc = doc.replace(/(<w:document\b[^>]*>)/, `$1<w:background w:color="${color}"/>`);
|
||||
const setBytes = files['word/settings.xml'];
|
||||
// Without this Word stores the colour but paints nothing.
|
||||
// Without this Word stores the colour but paints nothing. The docx package already
|
||||
// writes one; a duplicate breaks the CT_Settings sequence and Word repairs the file.
|
||||
if (setBytes) {
|
||||
files['word/settings.xml'] = strToU8(
|
||||
strFromU8(setBytes).replace(/(<w:settings\b[^>]*>)/, '$1<w:displayBackgroundShape/>'),
|
||||
);
|
||||
const settings = strFromU8(setBytes);
|
||||
if (!settings.includes('<w:displayBackgroundShape')) {
|
||||
files['word/settings.xml'] = strToU8(
|
||||
settings.replace(/(<w:settings\b[^>]*>)/, '$1<w:displayBackgroundShape/>'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,8 @@ describe.skipIf(!hasXmllint)('exported XML validates against the format schemas'
|
||||
sheet, undefined, 'add', false, opts.notesSettings, opts.props, true,
|
||||
opts.pageNumbering, opts.decor, opts.lineNumbering, true, true));
|
||||
docx = unzipSync(await buildDocx(doc, undefined, 'portrait', opts.hf, opts.language, 'A4',
|
||||
sheet, undefined, 'add', false, opts.notesSettings, opts.props, true, opts.pageNumbering));
|
||||
sheet, undefined, 'add', false, opts.notesSettings, opts.props, true,
|
||||
opts.pageNumbering, opts.decor, opts.lineNumbering, true, true));
|
||||
});
|
||||
|
||||
it('every ODF part is schema-valid (foreign namespaces stripped, as extended conformance allows)', () => {
|
||||
|
||||
Reference in new issue
Block a user