From 0e2bfe9e3fae9d39ddd4b86f82765a60d8a4ef2e Mon Sep 17 00:00:00 2001 From: Matt Walsh <51417385+netbymatt@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:53:29 -0600 Subject: [PATCH 1/4] Allow styles and headings with numbering --- src/file/paragraph/properties.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index b12bfedd8e..b87ef6b37a 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -125,8 +125,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { } if (options.numbering) { - if (!options.numbering.custom) { + if(!options.style && !options.heading) { + if (!options.numbering.custom) { this.push(new Style("ListParagraph")); + } } this.push(new NumberProperties(options.numbering.reference, options.numbering.level)); } From acaaf98e2029a26f5379eecbac124f2763b6ca86 Mon Sep 17 00:00:00 2001 From: Matt Walsh <51417385+netbymatt@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:21:15 -0600 Subject: [PATCH 2/4] Fix spacing --- src/file/paragraph/properties.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index b87ef6b37a..88d7c09ecc 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -125,7 +125,7 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { } if (options.numbering) { - if(!options.style && !options.heading) { + if (!options.style && !options.heading) { if (!options.numbering.custom) { this.push(new Style("ListParagraph")); } From 49314ea9d09561fcea2c877ba6d3f2deca868fc4 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 4 Feb 2021 14:48:57 -0600 Subject: [PATCH 3/4] fix prettier whitespace --- src/file/paragraph/properties.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 88d7c09ecc..2f08ce48d7 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -126,9 +126,9 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { if (options.numbering) { if (!options.style && !options.heading) { - if (!options.numbering.custom) { - this.push(new Style("ListParagraph")); - } + if (!options.numbering.custom) { + this.push(new Style("ListParagraph")); + } } this.push(new NumberProperties(options.numbering.reference, options.numbering.level)); } From 4b5d2d98f9cd368b3a120f4f9db6663873eb76e6 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Thu, 11 Mar 2021 11:11:46 -0600 Subject: [PATCH 4/4] add tests for numbering paragraph styles --- src/file/paragraph/paragraph.spec.ts | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index a368684d40..5f4a3dabd0 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -596,6 +596,36 @@ describe("Paragraph", () => { }); }); + it("should add a style to the list paragraph when provided", () => { + const paragraph = new Paragraph({ + numbering: { + reference: "test id", + level: 0, + }, + style: "myFancyStyle", + }); + const tree = new Formatter().format(paragraph); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ + "w:pStyle": { _attr: { "w:val": "myFancyStyle" } }, + }); + }); + + it("should not add ListParagraph style to a list when using custom numbering", () => { + const paragraph = new Paragraph({ + numbering: { + reference: "test id", + level: 0, + custom: true, + }, + }); + const tree = new Formatter().format(paragraph); + expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); + expect(tree["w:p"][0]["w:pPr"][0]).to.not.have.property("w:pStyle"); + }); + it("it should add numbered properties", () => { const paragraph = new Paragraph({ numbering: {