diff --git a/.nycrc b/.nycrc index 5afadd762c..6bb0274e3f 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 97.86, - "functions": 94.33, - "branches": 94.99, - "statements": 97.85, + "lines": 98.19, + "functions": 94.79, + "branches": 95.23, + "statements": 98.17, "include": [ "src/**/*.ts" ], diff --git a/src/file/paragraph/formatting/alignment.spec.ts b/src/file/paragraph/formatting/alignment.spec.ts new file mode 100644 index 0000000000..cb2a5babce --- /dev/null +++ b/src/file/paragraph/formatting/alignment.spec.ts @@ -0,0 +1,19 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { Alignment, AlignmentType } from "./alignment"; + +describe("Alignment", () => { + it("should create", () => { + const alignment = new Alignment(AlignmentType.BOTH); + const tree = new Formatter().format(alignment); + + expect(tree).to.deep.equal({ + "w:jc": { + _attr: { + "w:val": "both", + }, + }, + }); + }); +}); diff --git a/src/file/paragraph/formatting/widow-control.spec.ts b/src/file/paragraph/formatting/widow-control.spec.ts new file mode 100644 index 0000000000..e6e50fb13c --- /dev/null +++ b/src/file/paragraph/formatting/widow-control.spec.ts @@ -0,0 +1,20 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { WidowControl } from "./widow-control"; + +describe("WidowControl", () => { + it("should create", () => { + const widowControl = new WidowControl(true); + const tree = new Formatter().format(widowControl); + + expect(tree).to.deep.equal({ + "w:widowControl": { + _attr: { + "w:val": true, + }, + }, + }); + }); +}); diff --git a/src/file/paragraph/formatting/widow-control.ts b/src/file/paragraph/formatting/widow-control.ts new file mode 100644 index 0000000000..cbfc125564 --- /dev/null +++ b/src/file/paragraph/formatting/widow-control.ts @@ -0,0 +1,13 @@ +// http://www.datypic.com/sc/ooxml/e-w_widowControl-1.html +import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; + +export class WidowControlAttributes extends XmlAttributeComponent<{ readonly val: boolean }> { + protected readonly xmlKeys = { val: "w:val" }; +} + +export class WidowControl extends XmlComponent { + constructor(value: boolean) { + super("w:widowControl"); + this.root.push(new WidowControlAttributes({ val: value })); + } +} diff --git a/src/file/paragraph/properties.spec.ts b/src/file/paragraph/properties.spec.ts index 538131f29e..deb7f416c2 100644 --- a/src/file/paragraph/properties.spec.ts +++ b/src/file/paragraph/properties.spec.ts @@ -14,7 +14,7 @@ describe("ParagraphProperties", () => { expect(() => new Formatter().format(properties)).to.throw("XMLComponent did not format correctly"); }); - it("should create", () => { + it("should create with numbering", () => { const properties = new ParagraphProperties({ numbering: { reference: "test-reference", @@ -65,5 +65,35 @@ describe("ParagraphProperties", () => { ], }); }); + + it("should create with widowControl", () => { + const properties = new ParagraphProperties({ + widowControl: true, + }); + const tree = new Formatter().format(properties, { + // tslint:disable-next-line: no-object-literal-type-assertion + file: { + Numbering: { + createConcreteNumberingInstance: (_: string, __: number) => { + return; + }, + }, + } as File, + // tslint:disable-next-line: no-object-literal-type-assertion + viewWrapper: new DocumentWrapper({ background: {} }), + }); + + expect(tree).to.deep.equal({ + "w:pPr": [ + { + "w:widowControl": { + _attr: { + "w:val": true, + }, + }, + }, + ], + }); + }); }); }); diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 231482be78..e8fc29a713 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -12,6 +12,7 @@ import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spa import { HeadingLevel, Style } from "./formatting/style"; import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop"; import { NumberProperties } from "./formatting/unordered-list"; +import { WidowControl } from "./formatting/widow-control"; import { OutlineLevel } from "./links"; import { Shading } from "./run/formatting"; @@ -53,6 +54,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp readonly fill: string; readonly color: string; }; + readonly widowControl?: boolean; } export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { @@ -153,6 +155,10 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { if (options.shading) { this.push(new Shading(options.shading.type, options.shading.fill, options.shading.color)); } + + if (options.widowControl) { + this.push(new WidowControl(options.widowControl)); + } } public push(item: XmlComponent): void {