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

36 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-09-26 02:17:39 +01:00
// http://officeopenxml.com/WPtableOfContents.php
// http://www.datypic.com/sc/ooxml/e-w_sdt-1.html
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";
2018-09-26 02:17:39 +01:00
import { FieldInstruction } from "./field-instruction";
import { StructuredDocumentTagContent } from "./sdt-content";
import { StructuredDocumentTagProperties } from "./sdt-properties";
import { ITableOfContentsOptions } from "./table-of-contents-properties";
2018-08-21 07:19:46 -03:00
export class TableOfContents extends XmlComponent {
constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) {
2018-09-21 11:16:14 -03:00
super("w:sdt");
2018-09-26 02:17:39 +01:00
this.root.push(new StructuredDocumentTagProperties(alias));
2018-08-29 12:06:01 -03:00
2018-09-26 02:17:39 +01:00
const content = new StructuredDocumentTagContent();
const beginParagraph = new Paragraph();
const beginRun = new Run();
beginRun.addChildElement(new Begin(true));
2018-09-26 02:17:39 +01:00
beginRun.addChildElement(new FieldInstruction(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
}
}