TOC content generation aborted
This commit is contained in:
@ -1,2 +1 @@
|
||||
export * from "./table-of-contents";
|
||||
export * from "./page-reference-instruction";
|
||||
|
@ -1,13 +0,0 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class PageReferenceInstruction extends XmlComponent {
|
||||
constructor(bookmarkId: string) {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
this.root.push(`PAGEREF ${bookmarkId} \h`);
|
||||
}
|
||||
}
|
@ -1,12 +1,7 @@
|
||||
import { Paragraph } from "file/paragraph";
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class SdtContent extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:sdtContent");
|
||||
}
|
||||
|
||||
public addGeneratedContent(paragraph: Paragraph): void {
|
||||
this.root.splice(this.root.length - 1, 0, paragraph);
|
||||
}
|
||||
}
|
||||
|
@ -8,41 +8,26 @@ import { SdtProperties } from "./sdt-properties";
|
||||
import { TableOfContentsInstruction } from "./table-of-contents-instruction";
|
||||
|
||||
export class TableOfContents extends XmlComponent {
|
||||
// private readonly tocProperties: TableOfContentsProperties;
|
||||
private readonly properties: SdtProperties;
|
||||
|
||||
private readonly content: SdtContent;
|
||||
|
||||
private readonly instruction: TableOfContentsInstruction;
|
||||
|
||||
constructor(/*tocProperties?: TableOfContentsProperties*/) {
|
||||
constructor() {
|
||||
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);
|
||||
// this.tocProperties = tocProperties || new TableOfContentsProperties();
|
||||
this.root.push(new SdtProperties("Table of Contents"));
|
||||
|
||||
const content = new SdtContent();
|
||||
|
||||
const beginParagraph = new Paragraph();
|
||||
const beginRun = new Run();
|
||||
beginRun.addChildElement(new Begin(true));
|
||||
beginRun.addChildElement(this.instruction);
|
||||
beginRun.addChildElement(new TableOfContentsInstruction());
|
||||
beginRun.addChildElement(new Separate());
|
||||
beginParagraph.addRun(beginRun);
|
||||
this.content.addChildElement(beginParagraph);
|
||||
content.addChildElement(beginParagraph);
|
||||
|
||||
const endParagraph = new Paragraph();
|
||||
const endRun = new Run();
|
||||
endRun.addChildElement(new End());
|
||||
endParagraph.addRun(endRun);
|
||||
this.content.addChildElement(endParagraph);
|
||||
}
|
||||
content.addChildElement(endParagraph);
|
||||
|
||||
public getHeaderRange(): string {
|
||||
return this.instruction.getHeaderRange();
|
||||
}
|
||||
|
||||
public addGeneratedContent(paragraph: Paragraph): void {
|
||||
this.content.addGeneratedContent(paragraph);
|
||||
this.root.push(content);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user