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

69 lines
3.0 KiB
TypeScript
Raw Normal View History

2018-09-03 11:20:36 -03:00
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
2018-09-25 01:18:47 -03:00
import { TableOfContentsProperties } from "./table-of-contents-properties";
2018-09-03 11:20:36 -03:00
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
protected xmlKeys = { space: "xml:space" };
}
export class TableOfContentsInstruction extends XmlComponent {
2018-09-25 01:18:47 -03:00
private readonly properties: TableOfContentsProperties;
2018-09-25 01:18:47 -03:00
constructor(properties?: TableOfContentsProperties) {
2018-09-03 11:20:36 -03:00
super("w:instrText");
2018-09-25 01:18:47 -03:00
this.properties = properties || new TableOfContentsProperties();
2018-09-03 11:20:36 -03:00
this.root.push(new TextAttributes({ space: "preserve" }));
let instruction = "TOC";
2018-09-25 01:18:47 -03:00
if (this.properties.captionLabel) {
instruction = `${instruction} \\a "${this.properties.captionLabel}"`;
}
if (this.properties.entriesFromBookmark) {
instruction = `${instruction} \\b "${this.properties.entriesFromBookmark}"`;
}
if (this.properties.captionLabelIncludingNumbers) {
instruction = `${instruction} \\c "${this.properties.captionLabelIncludingNumbers}"`;
}
if (this.properties.sequenceAndPageNumbersSeparator) {
instruction = `${instruction} \\d "${this.properties.sequenceAndPageNumbersSeparator}"`;
}
if (this.properties.tcFieldIdentifier) {
instruction = `${instruction} \\f "${this.properties.tcFieldIdentifier}"`;
}
if (this.properties.hiperlink) {
2018-09-04 17:29:24 -03:00
instruction = `${instruction} \\h`;
}
2018-09-25 01:18:47 -03:00
if (this.properties.tcFieldLevelRange) {
instruction = `${instruction} \\l "${this.properties.tcFieldLevelRange}`;
}
if (this.properties.pageNumbersEntryLevelsRange) {
instruction = `${instruction} \\n "${this.properties.pageNumbersEntryLevelsRange}`;
}
2018-09-25 01:18:47 -03:00
if (this.properties.headingStyleRange) {
instruction = `${instruction} \\o "${this.properties.headingStyleRange}`;
}
2018-09-25 01:18:47 -03:00
if (this.properties.entryAndPageNumberSeparator) {
instruction = `${instruction} \\p "${this.properties.entryAndPageNumberSeparator}`;
}
if (this.properties.seqFieldIdentifierForPrefix) {
instruction = `${instruction} \\s "${this.properties.seqFieldIdentifierForPrefix}`;
}
if (this.properties.stylesWithLevels && this.properties.stylesWithLevels.length) {
const styles = this.properties.stylesWithLevels.map((sl) => `${sl.styleName},${sl.level}`).join(",");
2018-09-04 17:29:24 -03:00
instruction = `${instruction} \\t "${styles}"`;
}
2018-09-25 01:18:47 -03:00
if (this.properties.useAppliedParagraphOutlineLevel) {
instruction = `${instruction} \\u`;
}
if (this.properties.preserveTabInEntries) {
instruction = `${instruction} \\w`;
}
if (this.properties.preserveNewLineInEntries) {
instruction = `${instruction} \\x`;
}
if (this.properties.hideTabAndPageNumbersInWebView) {
instruction = `${instruction} \\z`;
}
this.root.push(instruction);
2018-09-03 11:20:36 -03:00
}
}