Merge pull request #169 from dolanmiu/feat/table-of-contents

Feat/table of contents
This commit is contained in:
Dolan
2018-09-26 02:28:44 +01:00
committed by GitHub
5 changed files with 14 additions and 9 deletions

View File

@ -16,6 +16,7 @@
* [Bullet Points](usage/bullet-points.md)
* [Numbering](usage/numbering.md)
* [Tab Stops](usage/tab-stops.md)
* [Table of Contents](usage/table-of-contents.md)
* Styling
* [Styling with JS](usage/styling-with-js.md)
* [Styling with XML](usage/styling-with-xml.md)

View File

@ -1,3 +1,4 @@
// http://officeopenxml.com/WPfieldInstructions.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { ITableOfContentsOptions } from "./table-of-contents-properties";
@ -10,7 +11,7 @@ class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
protected xmlKeys = { space: "xml:space" };
}
export class TableOfContentsInstruction extends XmlComponent {
export class FieldInstruction extends XmlComponent {
private readonly properties: ITableOfContentsOptions;
constructor(properties: ITableOfContentsOptions = {}) {

View File

@ -1,6 +1,6 @@
import { XmlComponent } from "file/xml-components";
export class SdtContent extends XmlComponent {
export class StructuredDocumentTagContent extends XmlComponent {
constructor() {
super("w:sdtContent");
}

View File

@ -1,7 +1,8 @@
// http://www.datypic.com/sc/ooxml/e-w_sdtPr-1.html
import { XmlComponent } from "file/xml-components";
import { Alias } from "./alias";
export class SdtProperties extends XmlComponent {
export class StructuredDocumentTagProperties extends XmlComponent {
constructor(alias: string) {
super("w:sdtPr");
this.root.push(new Alias(alias));

View File

@ -1,23 +1,25 @@
// http://officeopenxml.com/WPtableOfContents.php
// http://www.datypic.com/sc/ooxml/e-w_sdt-1.html
import { Paragraph } 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 { SdtContent } from "./sdt-content";
import { SdtProperties } from "./sdt-properties";
import { TableOfContentsInstruction } from "./table-of-contents-instruction";
import { FieldInstruction } from "./field-instruction";
import { StructuredDocumentTagContent } from "./sdt-content";
import { StructuredDocumentTagProperties } from "./sdt-properties";
import { ITableOfContentsOptions } from "./table-of-contents-properties";
export class TableOfContents extends XmlComponent {
constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) {
super("w:sdt");
this.root.push(new SdtProperties(alias));
this.root.push(new StructuredDocumentTagProperties(alias));
const content = new SdtContent();
const content = new StructuredDocumentTagContent();
const beginParagraph = new Paragraph();
const beginRun = new Run();
beginRun.addChildElement(new Begin(true));
beginRun.addChildElement(new TableOfContentsInstruction(properties));
beginRun.addChildElement(new FieldInstruction(properties));
beginRun.addChildElement(new Separate());
beginParagraph.addRun(beginRun);
content.addChildElement(beginParagraph);