Files
docx-js/src/file/table-of-contents/table-of-contents.ts

34 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Paragraph } from "file/paragraph";
2018-09-04 18:22:08 -03:00
import { Run } from "file/paragraph/run";
2018-09-03 11:20:36 -03:00
import { Begin, End, Separate } from "file/paragraph/run/field";
import { XmlComponent } from "file/xml-components";
import { SdtContent } from "./sdt-content";
import { SdtProperties } from "./sdt-properties";
import { TableOfContentsInstruction } from "./table-of-contents-instruction";
2018-09-25 20:05:35 +01:00
import { ITableOfContentsProperties } from "./table-of-contents-properties";
2018-08-21 07:19:46 -03:00
export class TableOfContents extends XmlComponent {
2018-09-25 20:05:35 +01:00
constructor(alias: string = "Table of Contents", properties?: ITableOfContentsProperties) {
2018-09-21 11:16:14 -03:00
super("w:sdt");
2018-09-25 01:18:47 -03:00
this.root.push(new SdtProperties(alias));
2018-08-29 12:06:01 -03:00
2018-09-21 11:16:14 -03:00
const content = new SdtContent();
const beginParagraph = new Paragraph();
const beginRun = new Run();
beginRun.addChildElement(new Begin(true));
2018-09-25 01:18:47 -03:00
beginRun.addChildElement(new TableOfContentsInstruction(properties));
beginRun.addChildElement(new Separate());
beginParagraph.addRun(beginRun);
2018-09-21 11:16:14 -03:00
content.addChildElement(beginParagraph);
const endParagraph = new Paragraph();
const endRun = new Run();
endRun.addChildElement(new End());
endParagraph.addRun(endRun);
2018-09-21 11:16:14 -03:00
content.addChildElement(endParagraph);
2018-09-04 18:22:08 -03:00
2018-09-21 11:16:14 -03:00
this.root.push(content);
2018-08-29 12:06:01 -03:00
}
}