generating the content for a table of contents

This commit is contained in:
Sergio Mendonça
2018-09-18 05:24:19 -03:00
parent 0eb36be053
commit 8e911698a5
13 changed files with 168 additions and 38 deletions

View File

@ -1,27 +1,42 @@
// import { TableOfContentsProperties } from "./properties";
import { ParagraphProperties } from "file/paragraph";
import { Paragraph, ParagraphProperties } from "file/paragraph";
import { Run } from "file/paragraph/run";
import { Begin, End, Separate } from "file/paragraph/run/field";
import { XmlComponent } from "file/xml-components";
import { TableOfContentsInstruction } from "./instruction";
import { TableOfContentsInstruction } from "./table-of-contents-instruction";
export class TableOfContents extends XmlComponent {
// private readonly tocProperties: TableOfContentsProperties;
private readonly properties: ParagraphProperties;
private readonly instruction: TableOfContentsInstruction;
constructor(/*tocProperties?: TableOfContentsProperties*/) {
super("w:p");
super("w:sdt");
this.properties = new ParagraphProperties();
this.instruction = new TableOfContentsInstruction();
this.root.push(this.properties);
// this.tocProperties = tocProperties || new TableOfContentsProperties();
const firstRun = new Run();
firstRun.addChildElement(new Begin());
firstRun.addChildElement(new TableOfContentsInstruction());
firstRun.addChildElement(new Separate());
this.root.push(firstRun);
const beginParagraph = new Paragraph();
const beginRun = new Run();
beginRun.addChildElement(new Begin());
beginRun.addChildElement(this.instruction);
beginRun.addChildElement(new Separate());
beginParagraph.addRun(beginRun);
this.root.push(beginParagraph);
const secondRun = new Run();
secondRun.addChildElement(new End());
this.root.push(secondRun);
const endParagraph = new Paragraph();
const endRun = new Run();
endRun.addChildElement(new End());
endParagraph.addRun(endRun);
this.root.push(endParagraph);
}
public getHeaderRange(): string {
return this.instruction.getHeaderRange();
}
public addGeneratedContent(paragraph: Paragraph): void {
this.root.splice(this.root.length - 1, 0, paragraph);
}
}