Merge pull request #2203 from dolanmiu/feature/do-not-override-default-styles
Fix override order in default styles
This commit is contained in:
@ -43,6 +43,15 @@ const doc = new Document({
|
|||||||
color: "#FF0000",
|
color: "#FF0000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
document: {
|
||||||
|
run: {
|
||||||
|
size: "11pt",
|
||||||
|
font: "Calibri",
|
||||||
|
},
|
||||||
|
paragraph: {
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
paragraphStyles: [
|
paragraphStyles: [
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,18 @@ import * as fs from "fs";
|
|||||||
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "docx";
|
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "docx";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
|
styles: {
|
||||||
|
default: {
|
||||||
|
hyperlink: {
|
||||||
|
run: {
|
||||||
|
color: "FF0000",
|
||||||
|
underline: {
|
||||||
|
color: "0000FF",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
footnotes: {
|
footnotes: {
|
||||||
1: {
|
1: {
|
||||||
children: [
|
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 {
|
export class HeadingStyle extends StyleForParagraph {
|
||||||
public constructor(options: IParagraphStyleOptions) {
|
public constructor(options: IParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
basedOn: "Normal",
|
basedOn: "Normal",
|
||||||
next: "Normal",
|
next: "Normal",
|
||||||
quickFormat: true,
|
quickFormat: true,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,9 +19,9 @@ export class HeadingStyle extends StyleForParagraph {
|
|||||||
export class TitleStyle extends HeadingStyle {
|
export class TitleStyle extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Title",
|
id: "Title",
|
||||||
name: "Title",
|
name: "Title",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,9 +29,9 @@ export class TitleStyle extends HeadingStyle {
|
|||||||
export class Heading1Style extends HeadingStyle {
|
export class Heading1Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading1",
|
id: "Heading1",
|
||||||
name: "Heading 1",
|
name: "Heading 1",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,9 +39,9 @@ export class Heading1Style extends HeadingStyle {
|
|||||||
export class Heading2Style extends HeadingStyle {
|
export class Heading2Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading2",
|
id: "Heading2",
|
||||||
name: "Heading 2",
|
name: "Heading 2",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,9 +49,9 @@ export class Heading2Style extends HeadingStyle {
|
|||||||
export class Heading3Style extends HeadingStyle {
|
export class Heading3Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading3",
|
id: "Heading3",
|
||||||
name: "Heading 3",
|
name: "Heading 3",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,9 +59,9 @@ export class Heading3Style extends HeadingStyle {
|
|||||||
export class Heading4Style extends HeadingStyle {
|
export class Heading4Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading4",
|
id: "Heading4",
|
||||||
name: "Heading 4",
|
name: "Heading 4",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,9 +69,9 @@ export class Heading4Style extends HeadingStyle {
|
|||||||
export class Heading5Style extends HeadingStyle {
|
export class Heading5Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading5",
|
id: "Heading5",
|
||||||
name: "Heading 5",
|
name: "Heading 5",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,9 +79,9 @@ export class Heading5Style extends HeadingStyle {
|
|||||||
export class Heading6Style extends HeadingStyle {
|
export class Heading6Style extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Heading6",
|
id: "Heading6",
|
||||||
name: "Heading 6",
|
name: "Heading 6",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,9 +89,9 @@ export class Heading6Style extends HeadingStyle {
|
|||||||
export class StrongStyle extends HeadingStyle {
|
export class StrongStyle extends HeadingStyle {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Strong",
|
id: "Strong",
|
||||||
name: "Strong",
|
name: "Strong",
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,11 +99,11 @@ export class StrongStyle extends HeadingStyle {
|
|||||||
export class ListParagraph extends StyleForParagraph {
|
export class ListParagraph extends StyleForParagraph {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "ListParagraph",
|
id: "ListParagraph",
|
||||||
name: "List Paragraph",
|
name: "List Paragraph",
|
||||||
basedOn: "Normal",
|
basedOn: "Normal",
|
||||||
quickFormat: true,
|
quickFormat: true,
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +111,6 @@ export class ListParagraph extends StyleForParagraph {
|
|||||||
export class FootnoteText extends StyleForParagraph {
|
export class FootnoteText extends StyleForParagraph {
|
||||||
public constructor(options: IBaseParagraphStyleOptions) {
|
public constructor(options: IBaseParagraphStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "FootnoteText",
|
id: "FootnoteText",
|
||||||
name: "footnote text",
|
name: "footnote text",
|
||||||
link: "FootnoteTextChar",
|
link: "FootnoteTextChar",
|
||||||
@ -129,6 +128,7 @@ export class FootnoteText extends StyleForParagraph {
|
|||||||
run: {
|
run: {
|
||||||
size: 20,
|
size: 20,
|
||||||
},
|
},
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,6 @@ export class FootnoteText extends StyleForParagraph {
|
|||||||
export class FootnoteReferenceStyle extends StyleForCharacter {
|
export class FootnoteReferenceStyle extends StyleForCharacter {
|
||||||
public constructor(options: IBaseCharacterStyleOptions) {
|
public constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "FootnoteReference",
|
id: "FootnoteReference",
|
||||||
name: "footnote reference",
|
name: "footnote reference",
|
||||||
basedOn: "DefaultParagraphFont",
|
basedOn: "DefaultParagraphFont",
|
||||||
@ -144,6 +143,7 @@ export class FootnoteReferenceStyle extends StyleForCharacter {
|
|||||||
run: {
|
run: {
|
||||||
superScript: true,
|
superScript: true,
|
||||||
},
|
},
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,6 @@ export class FootnoteReferenceStyle extends StyleForCharacter {
|
|||||||
export class FootnoteTextChar extends StyleForCharacter {
|
export class FootnoteTextChar extends StyleForCharacter {
|
||||||
public constructor(options: IBaseCharacterStyleOptions) {
|
public constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "FootnoteTextChar",
|
id: "FootnoteTextChar",
|
||||||
name: "Footnote Text Char",
|
name: "Footnote Text Char",
|
||||||
basedOn: "DefaultParagraphFont",
|
basedOn: "DefaultParagraphFont",
|
||||||
@ -160,6 +159,7 @@ export class FootnoteTextChar extends StyleForCharacter {
|
|||||||
run: {
|
run: {
|
||||||
size: 20,
|
size: 20,
|
||||||
},
|
},
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +167,6 @@ export class FootnoteTextChar extends StyleForCharacter {
|
|||||||
export class HyperlinkStyle extends StyleForCharacter {
|
export class HyperlinkStyle extends StyleForCharacter {
|
||||||
public constructor(options: IBaseCharacterStyleOptions) {
|
public constructor(options: IBaseCharacterStyleOptions) {
|
||||||
super({
|
super({
|
||||||
...options,
|
|
||||||
id: "Hyperlink",
|
id: "Hyperlink",
|
||||||
name: "Hyperlink",
|
name: "Hyperlink",
|
||||||
basedOn: "DefaultParagraphFont",
|
basedOn: "DefaultParagraphFont",
|
||||||
@ -177,6 +176,7 @@ export class HyperlinkStyle extends StyleForCharacter {
|
|||||||
type: UnderlineType.SINGLE,
|
type: UnderlineType.SINGLE,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user