Files
docx-js/ts/docx/paragraph.ts

105 lines
2.2 KiB
TypeScript
Raw Normal View History

2016-03-29 22:55:37 +01:00
import {XmlComponent, Attributes, ParagraphProperties, Run} from "./xml-components";
2016-03-29 05:01:33 +01:00
import {ThematicBreak} from "./border";
2016-03-28 03:55:33 +01:00
2016-03-29 04:10:33 +01:00
class Style {
2016-03-29 22:55:37 +01:00
private pStyle: Array<XmlComponent>;
2016-03-29 04:10:33 +01:00
constructor(type: string) {
2016-03-29 22:55:37 +01:00
this.pStyle = new Array<XmlComponent>();
2016-03-29 04:50:23 +01:00
this.pStyle.push(new Attributes({
val: type
}));
2016-03-29 04:10:33 +01:00
}
}
class Alignment {
2016-03-29 22:55:37 +01:00
private jc: Array<XmlComponent>;
2016-03-29 04:10:33 +01:00
constructor(type: string) {
2016-03-29 22:55:37 +01:00
this.jc = new Array<XmlComponent>();
2016-03-29 04:50:23 +01:00
this.jc.push(new Attributes({
val: type
}));
2016-03-29 04:10:33 +01:00
}
}
2016-03-28 00:53:24 +01:00
export class Paragraph {
2016-03-29 22:55:37 +01:00
private p: Array<XmlComponent>;
2016-03-29 04:10:33 +01:00
private properties: ParagraphProperties;
2016-03-28 03:55:33 +01:00
constructor(text?: string) {
2016-03-29 22:55:37 +01:00
this.p = new Array<XmlComponent>();
2016-03-28 03:55:33 +01:00
this.p.push(new Attributes());
2016-03-29 04:10:33 +01:00
this.properties = new ParagraphProperties();
this.p.push(this.properties);
2016-03-28 03:55:33 +01:00
this.p.push(new Run(text));
2016-03-27 02:28:47 +01:00
}
2016-03-29 04:10:33 +01:00
addText(run: Run) {
this.p.push(run);
return this;
}
heading1() {
this.properties.push(new Style("Heading1"));
return this;
}
heading2() {
this.properties.push(new Style("Heading2"));
return this;
}
heading3() {
this.properties.push(new Style("Heading3"));
return this;
}
heading4() {
this.properties.push(new Style("Heading4"));
return this;
}
heading5() {
this.properties.push(new Style("Heading5"));
return this;
}
title() {
this.properties.push(new Style("Title"));
return this;
}
center() {
this.properties.push(new Alignment("center"));
return this;
}
left() {
this.properties.push(new Alignment("left"));
return this;
}
right() {
this.properties.push(new Alignment("right"));
return this;
}
justified() {
this.properties.push(new Alignment("both"));
return this;
}
2016-03-29 05:01:33 +01:00
2016-03-29 23:36:57 +01:00
thematicBreak() {
2016-03-29 05:01:33 +01:00
this.properties.push(new ThematicBreak());
return this;
}
2016-03-29 23:36:57 +01:00
pageBreak () {
this.properties.push(new ThematicBreak());
paragraphProperties.push(pBreak);
return this;
}
2016-03-27 02:28:47 +01:00
}