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

112 lines
2.6 KiB
TypeScript
Raw Normal View History

2016-03-30 00:28:05 +01:00
import {XmlComponent, Attributes} from "../xml-components";
2016-03-29 05:01:33 +01:00
import {ThematicBreak} from "./border";
2016-03-30 00:28:05 +01:00
import {PageBreak} from "./page-break";
2016-03-30 03:50:53 +01:00
import {TextRun} from "../run/text-run";
2016-03-30 00:28:05 +01:00
import {ParagraphProperties} from "./properties";
2016-05-18 17:06:21 +01:00
import {MaxRightTabStop, LeftTabStop} from "./tab-stop";
2016-03-30 02:55:11 +01:00
import {Style} from "./style";
import {NumberProperties} from "./unordered-list";
2016-03-29 04:10:33 +01:00
2016-04-09 20:16:35 +01:00
class Alignment extends XmlComponent {
2016-03-29 04:10:33 +01:00
constructor(type: string) {
2016-04-09 20:16:35 +01:00
super("w:jc");
this.root.push(new Attributes({
2016-03-29 04:50:23 +01:00
val: type
}));
2016-03-29 04:10:33 +01:00
}
}
2016-04-09 20:16:35 +01:00
export class Paragraph extends XmlComponent {
2016-03-29 04:10:33 +01:00
private properties: ParagraphProperties;
2016-03-28 03:55:33 +01:00
constructor(text?: string) {
2016-04-09 20:16:35 +01:00
super("w:p");
2016-03-29 04:10:33 +01:00
this.properties = new ParagraphProperties();
2016-04-09 20:16:35 +01:00
this.root.push(this.properties);
if (text !== undefined) {
this.root.push(new TextRun(text));
}
2016-03-27 02:28:47 +01:00
}
2016-03-29 04:10:33 +01:00
2016-03-30 04:31:53 +01:00
addText(run: TextRun): Paragraph {
2016-04-09 20:16:35 +01:00
this.root.push(run);
2016-03-29 04:10:33 +01:00
return this;
}
2016-03-30 04:31:53 +01:00
heading1(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading1"));
return this;
}
2016-03-30 04:31:53 +01:00
heading2(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading2"));
return this;
}
2016-03-30 04:31:53 +01:00
heading3(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading3"));
return this;
}
2016-03-30 04:31:53 +01:00
heading4(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading4"));
return this;
}
2016-03-30 04:31:53 +01:00
heading5(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading5"));
return this;
}
2016-03-30 04:31:53 +01:00
title(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Title"));
return this;
}
2016-03-30 04:31:53 +01:00
center(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("center"));
return this;
}
2016-03-30 04:31:53 +01:00
left(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("left"));
return this;
}
2016-03-30 04:31:53 +01:00
right(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("right"));
return this;
}
2016-03-30 04:31:53 +01:00
justified(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("both"));
return this;
}
2016-03-29 05:01:33 +01:00
2016-03-30 04:31:53 +01:00
thematicBreak(): Paragraph {
2016-03-29 05:01:33 +01:00
this.properties.push(new ThematicBreak());
return this;
}
2016-03-29 23:36:57 +01:00
2016-03-30 04:31:53 +01:00
pageBreak(): Paragraph {
2016-03-30 00:28:05 +01:00
this.properties.push(new PageBreak());
return this;
}
2016-03-30 02:55:11 +01:00
2016-05-18 17:06:21 +01:00
maxRightTabStop(): Paragraph {
this.properties.push(new MaxRightTabStop());
return this;
}
leftTabStop(position: number): Paragraph {
this.properties.push(new LeftTabStop(position))
2016-03-30 02:55:11 +01:00
return this;
}
2016-03-30 04:31:53 +01:00
bullet(): Paragraph {
2016-03-30 02:55:11 +01:00
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties());
return this;
}
2016-03-27 02:28:47 +01:00
}