From 3dbd917667a6b3d229ca37f73893f3da8e09f964 Mon Sep 17 00:00:00 2001 From: felipe Date: Sun, 12 Mar 2017 17:31:36 +0100 Subject: [PATCH] added #color and #size methods to Run --- ts/docx/run/index.ts | 12 +++++++++++- ts/tests/docx/run/runTest.ts | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ts/docx/run/index.ts b/ts/docx/run/index.ts index 80417d05fb..bf974ed29b 100644 --- a/ts/docx/run/index.ts +++ b/ts/docx/run/index.ts @@ -1,6 +1,6 @@ import { Break } from "./break"; import { Caps, SmallCaps } from "./caps"; -import { Bold, Italics } from "./formatting"; +import { Bold, Color, Italics, Size } from "./formatting"; import { RunProperties } from "./properties"; import { RunFonts } from "./run-fonts"; import { SubScript, SuperScript } from "./script"; @@ -34,6 +34,16 @@ export class Run extends XmlComponent { return this; } + public color(color: string): Run { + this.properties.push(new Color(color)); + return this; + } + + public size(size: number): Run { + this.properties.push(new Size(size)); + return this; + } + public break(): Run { this.root.splice(1, 0, new Break()); return this; diff --git a/ts/tests/docx/run/runTest.ts b/ts/tests/docx/run/runTest.ts index a4587a05c8..42e180bba7 100644 --- a/ts/tests/docx/run/runTest.ts +++ b/ts/tests/docx/run/runTest.ts @@ -117,4 +117,28 @@ describe("Run", () => { }); }); }); + + describe("#color", () => { + it("should set the run to the color given", () => { + run.color("001122"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + {"w:rPr": [{"w:color": [{_attr: {"w:val": "001122"}}]}]}, + ], + }); + }); + }); + + describe("#size", () => { + it("should set the run to the given size", () => { + run.size(24); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + {"w:rPr": [{"w:sz": [{_attr: {"w:val": 24}}]}]}, + ], + }); + }); + }); });