From 18ca93e50a2d9e3a4342bc675f8b68dc21613b4d Mon Sep 17 00:00:00 2001 From: felipe Date: Thu, 9 Mar 2017 09:46:12 +0100 Subject: [PATCH] add paragraph#style method to quickly set the style --- ts/docx/paragraph/indent.ts | 2 +- ts/docx/paragraph/index.ts | 5 +++++ ts/tests/docx/paragraph/paragraphTests.ts | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ts/docx/paragraph/indent.ts b/ts/docx/paragraph/indent.ts index 24a73cb3e8..c98b3570a1 100644 --- a/ts/docx/paragraph/indent.ts +++ b/ts/docx/paragraph/indent.ts @@ -1,4 +1,4 @@ -import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components"; +import { XmlAttributeComponent, XmlComponent } from "../xml-components"; interface IndentAttributesProperties { left: number; diff --git a/ts/docx/paragraph/index.ts b/ts/docx/paragraph/index.ts index e22badcba5..7b82b63434 100644 --- a/ts/docx/paragraph/index.ts +++ b/ts/docx/paragraph/index.ts @@ -119,6 +119,11 @@ export class Paragraph extends XmlComponent { return this; } + public style(styleId: string): Paragraph { + this.properties.push(new Style(styleId)); + return this; + } + public indent(start: number, hanging?: number): Paragraph { this.properties.push(new Indent(start, hanging)); return this; diff --git a/ts/tests/docx/paragraph/paragraphTests.ts b/ts/tests/docx/paragraph/paragraphTests.ts index e581bf11f9..96b23ac8bd 100644 --- a/ts/tests/docx/paragraph/paragraphTests.ts +++ b/ts/tests/docx/paragraph/paragraphTests.ts @@ -155,6 +155,23 @@ describe("Paragraph", () => { }); }); + describe("#style", () => { + it("should set the paragraph style to the given styleId", () => { + paragraph.style('myFancyStyle'); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:pPr": [ + {"_attr": {}}, + {"w:pStyle": [{"_attr": {"w:val": "myFancyStyle"}}]}, + ], + }, + ] + }) + }); + }); + describe("#indent", () => { it("should set the paragraph indent to the given values", () => { paragraph.indent(720);