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

157 lines
4.1 KiB
TypeScript
Raw Normal View History

2017-04-01 12:18:23 +01:00
import { IData } from "../../media/data";
import { Num } from "../../numbering/num";
import { Run } from "../run";
2017-03-13 23:41:14 +00:00
import { PictureRun } from "../run/picture-run";
2017-03-08 21:36:09 +00:00
import { TextRun } from "../run/text-run";
import { XmlComponent } from "../xml-components";
import { Alignment } from "./alignment";
2017-03-08 21:36:09 +00:00
import { ThematicBreak } from "./border";
import { Indent } from "./indent";
import { KeepLines, KeepNext } from "./keep";
2017-03-08 21:36:09 +00:00
import { PageBreak } from "./page-break";
import { ParagraphProperties } from "./properties";
import { ISpacingProperties, Spacing } from "./spacing";
2017-03-08 21:36:09 +00:00
import { Style } from "./style";
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
import { NumberProperties } from "./unordered-list";
2016-03-29 04:10:33 +01:00
export * from "./formatting";
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
public addRun(run: Run): Paragraph {
2016-04-09 20:16:35 +01:00
this.root.push(run);
2016-03-29 04:10:33 +01:00
return this;
}
public createTextRun(text: string): TextRun {
2017-03-10 14:35:37 +01:00
const run = new TextRun(text);
this.addRun(run);
2017-03-10 14:35:37 +01:00
return run;
}
2017-04-01 12:18:23 +01:00
public createPictureRun(imageData: IData): PictureRun {
const run = new PictureRun(imageData);
2017-03-13 23:41:14 +00:00
this.addRun(run);
return run;
}
2017-03-08 21:36:09 +00:00
public heading1(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading1"));
return this;
}
2017-03-08 21:36:09 +00:00
public heading2(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading2"));
return this;
}
2017-03-08 21:36:09 +00:00
public heading3(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading3"));
return this;
}
2017-03-08 21:36:09 +00:00
public heading4(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading4"));
return this;
}
2017-03-08 21:36:09 +00:00
public heading5(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Heading5"));
return this;
}
2017-03-08 21:36:09 +00:00
public title(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Style("Title"));
return this;
}
2017-03-08 21:36:09 +00:00
public center(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("center"));
return this;
}
2017-03-08 21:36:09 +00:00
public left(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("left"));
return this;
}
2017-03-08 21:36:09 +00:00
public right(): Paragraph {
2016-03-29 04:10:33 +01:00
this.properties.push(new Alignment("right"));
return this;
}
2017-03-08 21:36:09 +00:00
public 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
2017-03-08 21:36:09 +00:00
public thematicBreak(): Paragraph {
2017-09-15 08:37:57 -06:00
this.properties.push(new ThematicBreak());
2016-03-29 05:01:33 +01:00
return this;
}
2016-03-29 23:36:57 +01:00
2017-03-08 21:36:09 +00:00
public pageBreak(): Paragraph {
this.root.push(new PageBreak());
2016-03-30 00:28:05 +01:00
return this;
}
2016-03-30 02:55:11 +01:00
2017-03-08 21:36:09 +00:00
public maxRightTabStop(): Paragraph {
2016-05-18 17:06:21 +01:00
this.properties.push(new MaxRightTabStop());
return this;
}
2016-05-26 15:08:34 +01:00
2017-03-08 21:36:09 +00:00
public leftTabStop(position: number): Paragraph {
2016-05-26 15:08:34 +01:00
this.properties.push(new LeftTabStop(position));
2016-03-30 02:55:11 +01:00
return this;
}
2017-03-08 21:36:09 +00:00
public bullet(): Paragraph {
2016-03-30 02:55:11 +01:00
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(1, 0));
2016-03-30 02:55:11 +01:00
return this;
}
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
this.properties.push(new Style("ListParagraph"));
this.properties.push(new NumberProperties(numbering.id, indentLevel));
return this;
}
public style(styleId: string): Paragraph {
this.properties.push(new Style(styleId));
return this;
}
public indent(start: number, hanging?: number): Paragraph {
this.properties.push(new Indent(start, hanging));
return this;
}
public spacing(params: ISpacingProperties): Paragraph {
this.properties.push(new Spacing(params));
return this;
2017-04-15 17:54:47 +01:00
}
public keepNext(): Paragraph {
this.properties.push(new KeepNext());
return this;
}
public keepLines(): Paragraph {
this.properties.push(new KeepLines());
return this;
}
}