Fix override order in default styles
This commit is contained in:
@ -4,6 +4,18 @@ import * as fs from "fs";
|
||||
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
styles: {
|
||||
default: {
|
||||
hyperlink: {
|
||||
run: {
|
||||
color: "FF0000",
|
||||
underline: {
|
||||
color: "0000FF",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
footnotes: {
|
||||
1: {
|
||||
children: [
|
||||
|
@ -318,4 +318,45 @@ describe("Default Styles", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("HyperlinkStyle#constructor", () => {
|
||||
const style = new defaultStyles.HyperlinkStyle({
|
||||
run: {
|
||||
color: "FF0000",
|
||||
underline: {
|
||||
color: "0000FF",
|
||||
},
|
||||
},
|
||||
});
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "Hyperlink" } },
|
||||
{ "w:name": { _attr: { "w:val": "Hyperlink" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:u": { _attr: { "w:color": "0000FF", "w:val": "single" } } },
|
||||
{
|
||||
"w:color": {
|
||||
_attr: {
|
||||
"w:val": "FF0000",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -8,10 +8,10 @@ import { IBaseParagraphStyleOptions, IParagraphStyleOptions, StyleForParagraph }
|
||||
export class HeadingStyle extends StyleForParagraph {
|
||||
public constructor(options: IParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
basedOn: "Normal",
|
||||
next: "Normal",
|
||||
quickFormat: true,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -19,9 +19,9 @@ export class HeadingStyle extends StyleForParagraph {
|
||||
export class TitleStyle extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Title",
|
||||
name: "Title",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -29,9 +29,9 @@ export class TitleStyle extends HeadingStyle {
|
||||
export class Heading1Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading1",
|
||||
name: "Heading 1",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -39,9 +39,9 @@ export class Heading1Style extends HeadingStyle {
|
||||
export class Heading2Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading2",
|
||||
name: "Heading 2",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -49,9 +49,9 @@ export class Heading2Style extends HeadingStyle {
|
||||
export class Heading3Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading3",
|
||||
name: "Heading 3",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -59,9 +59,9 @@ export class Heading3Style extends HeadingStyle {
|
||||
export class Heading4Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading4",
|
||||
name: "Heading 4",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -69,9 +69,9 @@ export class Heading4Style extends HeadingStyle {
|
||||
export class Heading5Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading5",
|
||||
name: "Heading 5",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -79,9 +79,9 @@ export class Heading5Style extends HeadingStyle {
|
||||
export class Heading6Style extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Heading6",
|
||||
name: "Heading 6",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -89,9 +89,9 @@ export class Heading6Style extends HeadingStyle {
|
||||
export class StrongStyle extends HeadingStyle {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Strong",
|
||||
name: "Strong",
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -99,11 +99,11 @@ export class StrongStyle extends HeadingStyle {
|
||||
export class ListParagraph extends StyleForParagraph {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "ListParagraph",
|
||||
name: "List Paragraph",
|
||||
basedOn: "Normal",
|
||||
quickFormat: true,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,6 @@ export class ListParagraph extends StyleForParagraph {
|
||||
export class FootnoteText extends StyleForParagraph {
|
||||
public constructor(options: IBaseParagraphStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "FootnoteText",
|
||||
name: "footnote text",
|
||||
link: "FootnoteTextChar",
|
||||
@ -129,6 +128,7 @@ export class FootnoteText extends StyleForParagraph {
|
||||
run: {
|
||||
size: 20,
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,6 @@ export class FootnoteText extends StyleForParagraph {
|
||||
export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||
public constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "FootnoteReference",
|
||||
name: "footnote reference",
|
||||
basedOn: "DefaultParagraphFont",
|
||||
@ -144,6 +143,7 @@ export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||
run: {
|
||||
superScript: true,
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,6 @@ export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||
export class FootnoteTextChar extends StyleForCharacter {
|
||||
public constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "FootnoteTextChar",
|
||||
name: "Footnote Text Char",
|
||||
basedOn: "DefaultParagraphFont",
|
||||
@ -160,6 +159,7 @@ export class FootnoteTextChar extends StyleForCharacter {
|
||||
run: {
|
||||
size: 20,
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,6 @@ export class FootnoteTextChar extends StyleForCharacter {
|
||||
export class HyperlinkStyle extends StyleForCharacter {
|
||||
public constructor(options: IBaseCharacterStyleOptions) {
|
||||
super({
|
||||
...options,
|
||||
id: "Hyperlink",
|
||||
name: "Hyperlink",
|
||||
basedOn: "DefaultParagraphFont",
|
||||
@ -177,6 +176,7 @@ export class HyperlinkStyle extends StyleForCharacter {
|
||||
type: UnderlineType.SINGLE,
|
||||
},
|
||||
},
|
||||
...options,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user