Merge pull request #75 from h4buli/feature/page-break-before
paragraph: add support for 'page break before' format property
This commit is contained in:
14
demo/demo15.js
Normal file
14
demo/demo15.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const docx = require('../build');
|
||||||
|
|
||||||
|
var doc = new docx.Document();
|
||||||
|
|
||||||
|
var paragraph = new docx.Paragraph("Hello World");
|
||||||
|
var paragraph2 = new docx.Paragraph("Hello World on another page").pageBreakBefore();
|
||||||
|
|
||||||
|
doc.addParagraph(paragraph);
|
||||||
|
doc.addParagraph(paragraph2);
|
||||||
|
|
||||||
|
var exporter = new docx.LocalPacker(doc);
|
||||||
|
exporter.pack('My Document');
|
||||||
|
|
||||||
|
console.log('Document created successfully at project root!');
|
@ -1,7 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
|
||||||
import { Utility } from "../../../tests/utility";
|
import { Utility } from "../../../tests/utility";
|
||||||
import { PageBreak } from "./page-break";
|
import { PageBreak, PageBreakBefore } from "./page-break";
|
||||||
|
|
||||||
describe("PageBreak", () => {
|
describe("PageBreak", () => {
|
||||||
let pageBreak: 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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -19,3 +19,12 @@ export class PageBreak extends Run {
|
|||||||
this.root.push(new Break());
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -161,6 +161,24 @@ 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()", () => {
|
describe("#bullet()", () => {
|
||||||
it("should default to 0 indent level if no bullet was specified", () => {
|
it("should default to 0 indent level if no bullet was specified", () => {
|
||||||
paragraph.bullet();
|
paragraph.bullet();
|
||||||
|
@ -8,7 +8,7 @@ import { Alignment } from "./formatting/alignment";
|
|||||||
import { ThematicBreak } from "./formatting/border";
|
import { ThematicBreak } from "./formatting/border";
|
||||||
import { Indent } from "./formatting/indent";
|
import { Indent } from "./formatting/indent";
|
||||||
import { KeepLines, KeepNext } from "./formatting/keep";
|
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 { ISpacingProperties, Spacing } from "./formatting/spacing";
|
||||||
import { Style } from "./formatting/style";
|
import { Style } from "./formatting/style";
|
||||||
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
||||||
@ -115,6 +115,11 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public pageBreakBefore(): Paragraph {
|
||||||
|
this.properties.push(new PageBreakBefore());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public maxRightTabStop(): Paragraph {
|
public maxRightTabStop(): Paragraph {
|
||||||
this.properties.push(new MaxRightTabStop());
|
this.properties.push(new MaxRightTabStop());
|
||||||
return this;
|
return this;
|
||||||
|
Reference in New Issue
Block a user