Dont set background color if none is provided in options

After comparing the output of this library and what is
produced by Microsoft Word, it seems that document
background color is not set by default by Word.

Removing the default #FFFFFF background color enables the
generated documents to be readable in dark mode.

This seems to fix dolanmiu/docx#1093
This commit is contained in:
erlendaxelsson
2021-11-12 10:21:01 +01:00
parent 0757295213
commit ba963b0360
3 changed files with 5 additions and 9 deletions

View File

@ -6,14 +6,12 @@ import { DocumentBackground } from "./document-background";
describe("DocumentBackground", () => { describe("DocumentBackground", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a DocumentBackground with no options and set color to auto", () => { it("should create a DocumentBackground with no options", () => {
const documentBackground = new DocumentBackground({}); const documentBackground = new DocumentBackground({});
const tree = new Formatter().format(documentBackground); const tree = new Formatter().format(documentBackground);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:background": { "w:background": {
_attr: { _attr: {},
"w:color": "FFFFFF",
},
}, },
}); });
}); });

View File

@ -26,7 +26,7 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
// </xsd:simpleType> // </xsd:simpleType>
export class DocumentBackgroundAttributes extends XmlAttributeComponent<{ export class DocumentBackgroundAttributes extends XmlAttributeComponent<{
readonly color: string; readonly color?: string;
readonly themeColor?: string; readonly themeColor?: string;
readonly themeShade?: string; readonly themeShade?: string;
readonly themeTint?: string; readonly themeTint?: string;
@ -68,7 +68,7 @@ export class DocumentBackground extends XmlComponent {
this.root.push( this.root.push(
new DocumentBackgroundAttributes({ new DocumentBackgroundAttributes({
color: hexColorValue(options.color ? options.color : "FFFFFF"), color: options.color === undefined ? undefined : hexColorValue(options.color),
themeColor: options.themeColor, themeColor: options.themeColor,
themeShade: options.themeShade === undefined ? undefined : uCharHexNumber(options.themeShade), themeShade: options.themeShade === undefined ? undefined : uCharHexNumber(options.themeShade),
themeTint: options.themeTint === undefined ? undefined : uCharHexNumber(options.themeTint), themeTint: options.themeTint === undefined ? undefined : uCharHexNumber(options.themeTint),

View File

@ -40,9 +40,7 @@ describe("Document", () => {
}, },
{ {
"w:background": { "w:background": {
_attr: { _attr: {},
"w:color": "FFFFFF",
},
}, },
}, },
{ "w:body": {} }, { "w:body": {} },