added page break
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import {XmlComponent, Attributes} from "./xml-components";
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
|
||||
class Border implements XmlComponent {
|
||||
private bottom: Array<XmlComponent>;
|
@ -1,5 +1,8 @@
|
||||
import {XmlComponent, Attributes, ParagraphProperties, Run} from "./xml-components";
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import {ThematicBreak} from "./border";
|
||||
import {PageBreak} from "./page-break";
|
||||
import {TextRun} from "./text-run";
|
||||
import {ParagraphProperties} from "./properties";
|
||||
|
||||
class Style {
|
||||
private pStyle: Array<XmlComponent>;
|
||||
@ -32,10 +35,10 @@ export class Paragraph {
|
||||
this.p.push(new Attributes());
|
||||
this.properties = new ParagraphProperties();
|
||||
this.p.push(this.properties);
|
||||
this.p.push(new Run(text));
|
||||
this.p.push(new TextRun(text));
|
||||
}
|
||||
|
||||
addText(run: Run) {
|
||||
addText(run: TextRun) {
|
||||
this.p.push(run);
|
||||
return this;
|
||||
}
|
||||
@ -96,10 +99,7 @@ export class Paragraph {
|
||||
}
|
||||
|
||||
pageBreak() {
|
||||
this.properties.push(new ThematicBreak());
|
||||
|
||||
|
||||
paragraphProperties.push(pBreak);
|
||||
this.properties.push(new PageBreak());
|
||||
return this;
|
||||
}
|
||||
}
|
19
ts/docx/paragraph/page-break.ts
Normal file
19
ts/docx/paragraph/page-break.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {XmlComponent, Attributes, Run} from "../xml-components";
|
||||
|
||||
class Break implements XmlComponent {
|
||||
private br: Array<XmlComponent>;
|
||||
constructor() {
|
||||
this.br = new Array<XmlComponent>();
|
||||
this.br.push(new Attributes({
|
||||
type: "page"
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
export class PageBreak extends Run {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.r.push(new Break());
|
||||
}
|
||||
}
|
14
ts/docx/paragraph/properties.ts
Normal file
14
ts/docx/paragraph/properties.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
|
||||
export class ParagraphProperties implements XmlComponent {
|
||||
private pPr: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.pPr = new Array<XmlComponent>();
|
||||
this.pPr.push(new Attributes());
|
||||
}
|
||||
|
||||
push(item: XmlComponent) {
|
||||
this.pPr.push(item);
|
||||
}
|
||||
}
|
11
ts/docx/paragraph/text-run.ts
Normal file
11
ts/docx/paragraph/text-run.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import {Run, Text} from "../xml-components";
|
||||
import {ParagraphProperties} from "./properties";
|
||||
|
||||
export class TextRun extends Run {
|
||||
|
||||
constructor(text: string) {
|
||||
super();
|
||||
this.r.push(new ParagraphProperties());
|
||||
this.r.push(new Text(text));
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ interface AttributesProperties {
|
||||
color?: string;
|
||||
space?: string;
|
||||
sz?: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export class Attributes implements XmlComponent {
|
||||
@ -21,26 +22,11 @@ export class Attributes implements XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export class ParagraphProperties implements XmlComponent {
|
||||
private pPr: Array<XmlComponent>;
|
||||
export class Run implements XmlComponent {
|
||||
protected r: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.pPr = new Array<XmlComponent>();
|
||||
this.pPr.push(new Attributes());
|
||||
}
|
||||
|
||||
push(item: XmlComponent) {
|
||||
this.pPr.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
export class Run implements XmlComponent {
|
||||
private r: Array<XmlComponent>;
|
||||
|
||||
constructor(text: string) {
|
||||
this.r = new Array<XmlComponent>();
|
||||
this.r.push(new ParagraphProperties());
|
||||
this.r.push(new Text(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// <reference path="../typings/mocha/mocha.d.ts" />
|
||||
/// <reference path="../typings/chai/chai.d.ts" />
|
||||
import {ThematicBreak} from "../docx/border";
|
||||
import {ThematicBreak} from "../docx/paragraph/border";
|
||||
import {assert} from "chai";
|
||||
|
||||
function jsonify(obj: Object) {
|
||||
|
@ -85,4 +85,18 @@ describe('Paragraph', () => {
|
||||
assert.isDefined(newJson.p[1].pPr[1].pBdr);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#pageBreak()", () => {
|
||||
it("should add page break to JSON", () => {
|
||||
paragraph.pageBreak();
|
||||
var newJson = jsonify(paragraph);
|
||||
assert.isDefined(newJson.p[1].pPr[1].r[0].br);
|
||||
});
|
||||
|
||||
it("should add page break with 'page' type", () => {
|
||||
paragraph.pageBreak();
|
||||
var newJson = jsonify(paragraph);
|
||||
assert(newJson.p[1].pPr[1].r[0].br[0]._attrs.type === "page");
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user