fix: Ensure necessary namespaces are in patched doc (#2698)
* refactor: Extract timestamp properties In preparation for reworking DocumentAttributes. * refactor: Consolidate namespaces * fix: Ensure necessary namespaces are in patched doc Fixes #2697 * Fix tsc and ESLint errors * Fix CSpell * Add a test to fix code coverage failure
This commit is contained in:
@ -2,6 +2,7 @@ import JSZip from "jszip";
|
||||
import { Element, js2xml } from "xml-js";
|
||||
|
||||
import { ImageReplacer } from "@export/packer/image-replacer";
|
||||
import { DocumentAttributeNamespaces } from "@file/document";
|
||||
import { IViewWrapper } from "@file/document-wrapper";
|
||||
import { File } from "@file/file";
|
||||
import { FileChild } from "@file/file-child";
|
||||
@ -100,6 +101,24 @@ export const patchDocument = async <T extends PatchDocumentOutputType = PatchDoc
|
||||
}
|
||||
|
||||
const json = toJson(await value.async("text"));
|
||||
|
||||
if (key === "word/document.xml") {
|
||||
const document = json.elements?.find((i) => i.name === "w:document");
|
||||
if (document) {
|
||||
// We could check all namespaces from Document, but we'll instead
|
||||
// check only those that may be used by our element types.
|
||||
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
document.attributes = document.attributes ?? {};
|
||||
for (const ns of ["mc", "wp", "r", "w15", "m"] as const) {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
document.attributes[`xmlns:${ns}`] = DocumentAttributeNamespaces[ns];
|
||||
}
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
document.attributes["mc:Ignorable"] = `${document.attributes["mc:Ignorable"] || ""} w15`.trim();
|
||||
}
|
||||
}
|
||||
|
||||
if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
|
||||
const context: IContext = {
|
||||
file,
|
||||
|
Reference in New Issue
Block a user