generating the content for a table of contents
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user