From ac7799a875d7bb303b32482a32324f7119d00e3a Mon Sep 17 00:00:00 2001 From: felipe Date: Thu, 9 Mar 2017 13:19:50 +0100 Subject: [PATCH] add an #underline method to ParagraphStyle --- ts/styles/style/index.ts | 5 +++++ ts/tests/stylesTest.ts | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index ececdfe6bd..840e55b317 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -100,6 +100,11 @@ export class ParagraphStyle extends Style { return this; } + public underline(underlineType?: string, color?: string): ParagraphStyle { + this.addRunProperty(new formatting.Underline(underlineType, color)); + return this; + } + public color(color: string): ParagraphStyle { this.addRunProperty(new formatting.Color(color)); return this; diff --git a/ts/tests/stylesTest.ts b/ts/tests/stylesTest.ts index 9035e1c030..22441ec769 100644 --- a/ts/tests/stylesTest.ts +++ b/ts/tests/stylesTest.ts @@ -235,6 +235,53 @@ describe("ParagraphStyle", () => { }); }); + describe("#underline", () => { + it("should set underline to 'single' if no arguments are given", () => { + const style = new ParagraphStyle("myStyleId") + .underline(); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [{_attr: {}}]}, + {"w:rPr": [ + {"w:u": [{_attr: {"w:val": "single"}}]}, + ]}, + ], + }); + }); + + it("should set the style if given", () => { + const style = new ParagraphStyle("myStyleId") + .underline("double"); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [{_attr: {}}]}, + {"w:rPr": [ + {"w:u": [{_attr: {"w:val": "double"}}]}, + ]}, + ], + }); + }); + + it("should set the style and color if given", () => { + const style = new ParagraphStyle("myStyleId") + .underline("double", "005599"); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": [{_attr: {}}]}, + {"w:rPr": [ + {"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]}, + ]}, + ], + }); + }); + }); + it("#color", () => { const style = new ParagraphStyle("myStyleId") .color("123456");