fix: omit empty descr/title in <wp:docPr> for Word 2007 compatibility (#3073)

This commit is contained in:
Minh
2025-05-03 01:55:22 +07:00
committed by GitHub
parent c38d0a253e
commit 1e6c9e1772

View File

@ -19,8 +19,8 @@ import { createHyperlinkClick } from "./doc-properties-children";
export type DocPropertiesOptions = { export type DocPropertiesOptions = {
readonly name: string; readonly name: string;
readonly description: string; readonly description?: string;
readonly title: string; readonly title?: string;
}; };
export class DocProperties extends XmlComponent { export class DocProperties extends XmlComponent {
@ -29,26 +29,32 @@ export class DocProperties extends XmlComponent {
public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) { public constructor({ name, description, title }: DocPropertiesOptions = { name: "", description: "", title: "" }) {
super("wp:docPr"); super("wp:docPr");
this.root.push( const attributes: Record<string, { readonly key: string; readonly value: string | number }> = {
new NextAttributeComponent({ id: {
id: { key: "id",
key: "id", value: this.docPropertiesUniqueNumericId(),
value: this.docPropertiesUniqueNumericId(), },
}, name: {
name: { key: "name",
key: "name", value: name,
value: name, },
}, };
description: {
key: "descr", if (description !== null && description !== undefined) {
value: description, attributes.description = {
}, key: "descr",
title: { value: description,
key: "title", };
value: title, }
},
}), if (title !== null && title !== undefined) {
); attributes.title = {
key: "title",
value: title,
};
}
this.root.push(new NextAttributeComponent(attributes));
} }
public prepForXml(context: IContext): IXmlableObject | undefined { public prepForXml(context: IContext): IXmlableObject | undefined {
@ -59,7 +65,6 @@ export class DocProperties extends XmlComponent {
} }
this.root.push(createHyperlinkClick(element.linkId, true)); this.root.push(createHyperlinkClick(element.linkId, true));
break; break;
} }