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

49 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-08-31 10:22:40 -03:00
// import { TableOfContentsProperties } from "./properties";
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-08-21 07:19:46 -03:00
export class TableOfContents extends XmlComponent {
2018-08-31 10:22:40 -03:00
// private readonly tocProperties: TableOfContentsProperties;
private readonly properties: SdtProperties;
private readonly content: SdtContent;
2018-08-29 12:06:01 -03:00
private readonly instruction: TableOfContentsInstruction;
2018-08-31 10:22:40 -03:00
constructor(/*tocProperties?: TableOfContentsProperties*/) {
super("w:sdt");
this.properties = new SdtProperties("Table of Contents");
this.content = new SdtContent();
this.instruction = new TableOfContentsInstruction();
this.root.push(this.properties);
this.root.push(this.content);
2018-08-31 10:22:40 -03:00
// this.tocProperties = tocProperties || new TableOfContentsProperties();
const beginParagraph = new Paragraph();
const beginRun = new Run();
beginRun.addChildElement(new Begin());
beginRun.addChildElement(this.instruction);
beginRun.addChildElement(new Separate());
beginParagraph.addRun(beginRun);
this.content.addChildElement(beginParagraph);
const endParagraph = new Paragraph();
const endRun = new Run();
endRun.addChildElement(new End());
endParagraph.addRun(endRun);
this.content.addChildElement(endParagraph);
}
public getHeaderRange(): string {
return this.instruction.getHeaderRange();
}
2018-09-04 18:22:08 -03:00
public addGeneratedContent(paragraph: Paragraph): void {
this.content.addGeneratedContent(paragraph);
2018-08-29 12:06:01 -03:00
}
}