diff --git a/src/file/paragraph/formatting/page-break.spec.ts b/src/file/paragraph/formatting/page-break.spec.ts index 675ac5d112..6ba877311f 100644 --- a/src/file/paragraph/formatting/page-break.spec.ts +++ b/src/file/paragraph/formatting/page-break.spec.ts @@ -1,7 +1,7 @@ import { assert } from "chai"; import { Utility } from "../../../tests/utility"; -import { PageBreak } from "./page-break"; +import { PageBreak, PageBreakBefore } from "./page-break"; describe("PageBreak", () => { let pageBreak: PageBreak; @@ -30,3 +30,11 @@ describe("PageBreak", () => { }); }); }); + +describe("PageBreakBefore", () => { + it("should create page break before", () => { + const pageBreakBefore = new PageBreakBefore(); + const newJson = Utility.jsonify(pageBreakBefore); + assert.equal(newJson.rootKey, "w:pageBreakBefore"); + }); +}); diff --git a/src/file/paragraph/formatting/page-break.ts b/src/file/paragraph/formatting/page-break.ts index 1b4e6642b5..13556d12e2 100644 --- a/src/file/paragraph/formatting/page-break.ts +++ b/src/file/paragraph/formatting/page-break.ts @@ -19,3 +19,12 @@ export class PageBreak extends Run { this.root.push(new Break()); } } + +/** + * Add page break before the paragraph if there is no one added before. + */ +export class PageBreakBefore extends XmlComponent { + constructor() { + super("w:pageBreakBefore"); + } +} diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 54c5970679..0aa17b558a 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -161,6 +161,22 @@ describe("Paragraph", () => { }); }); + describe("#pageBreakBefore()", () => { + it("should add page break before to JSON", () => { + paragraph.pageBreakBefore(); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:pPr": [{ + "w:pageBreakBefore": [] + }], + } + ], + }); + }); + }); + describe("#bullet()", () => { it("should add list paragraph style to JSON", () => { paragraph.bullet(); diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index ac779de094..22839a491a 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -8,7 +8,7 @@ import { Alignment } from "./formatting/alignment"; import { ThematicBreak } from "./formatting/border"; import { Indent } from "./formatting/indent"; import { KeepLines, KeepNext } from "./formatting/keep"; -import { PageBreak } from "./formatting/page-break"; +import { PageBreak, PageBreakBefore } from "./formatting/page-break"; import { ISpacingProperties, Spacing } from "./formatting/spacing"; import { Style } from "./formatting/style"; import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop"; @@ -104,6 +104,11 @@ export class Paragraph extends XmlComponent { return this; } + public pageBreakBefore(): Paragraph { + this.properties.push(new PageBreakBefore()); + return this; + } + public maxRightTabStop(): Paragraph { this.properties.push(new MaxRightTabStop()); return this;