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

42 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";
import { Run } from "@file/paragraph/run";
import { Begin, End, Separate } from "@file/paragraph/run/field";
2023-01-23 14:14:05 +00:00
import { FileChild } from "@file/file-child";
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
2023-01-23 14:14:05 +00:00
export class TableOfContents extends FileChild {
2022-08-31 07:52:27 +01:00
public 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({
children: [
new Run({
children: [new Begin(true), new FieldInstruction(properties), new Separate()],
}),
],
});
2018-09-21 11:16:14 -03:00
content.addChildElement(beginParagraph);
const endParagraph = new Paragraph({
children: [
new Run({
children: [new End()],
}),
],
});
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
}
}