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,11 +1,14 @@
import { Attributes, XmlComponent } from "file/xml-components";
export class Style extends XmlComponent {
constructor(type: string) {
public readonly styleId: string;
constructor(styleId: string) {
super("w:pStyle");
this.styleId = styleId;
this.root.push(
new Attributes({
val: type,
val: styleId,
}),
);
}

View File

@ -2,25 +2,27 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export class TabStop extends XmlComponent {
constructor(tab: Tab) {
constructor(tab: TabStopItem) {
super("w:tabs");
this.root.push(tab);
}
}
export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start";
export type LeaderType = "dot" | "hyphen" | "middleDot" | "none" | "underscore";
export class TabAttributes extends XmlAttributeComponent<{ val: TabValue; pos: string | number }> {
protected xmlKeys = { val: "w:val", pos: "w:pos" };
export class TabAttributes extends XmlAttributeComponent<{ val: TabValue; pos: string | number; leader: LeaderType }> {
protected xmlKeys = { val: "w:val", pos: "w:pos", leader: "w:leader" };
}
export class Tab extends XmlComponent {
constructor(value: TabValue, position: string | number) {
export class TabStopItem extends XmlComponent {
constructor(value: TabValue, position: string | number, leader?: LeaderType) {
super("w:tab");
this.root.push(
new TabAttributes({
val: value,
pos: position,
leader: leader || "none",
}),
);
}
@ -28,24 +30,24 @@ export class Tab extends XmlComponent {
export class MaxRightTabStop extends TabStop {
constructor() {
super(new Tab("right", 9026));
super(new TabStopItem("right", 9026));
}
}
export class LeftTabStop extends TabStop {
constructor(position: number) {
super(new Tab("left", position));
constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("left", position, leader));
}
}
export class RightTabStop extends TabStop {
constructor(position: number) {
super(new Tab("right", position));
constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("right", position, leader));
}
}
export class CenterTabStop extends TabStop {
constructor(position: number) {
super(new Tab("center", position));
constructor(position: number, leader?: LeaderType) {
super(new TabStopItem("center", position, leader));
}
}

View File

@ -12,7 +12,7 @@ import { KeepLines, KeepNext } from "./formatting/keep";
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
import { ISpacingProperties, Spacing } from "./formatting/spacing";
import { Style } from "./formatting/style";
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
import { CenterTabStop, LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
import { NumberProperties } from "./formatting/unordered-list";
import { Bookmark, Hyperlink } from "./links";
import { ParagraphProperties } from "./properties";
@ -160,18 +160,18 @@ export class Paragraph extends XmlComponent {
return this;
}
public leftTabStop(position: number): Paragraph {
this.properties.push(new LeftTabStop(position));
public leftTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new LeftTabStop(position, leader));
return this;
}
public rightTabStop(position: number): Paragraph {
this.properties.push(new RightTabStop(position));
public rightTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new RightTabStop(position, leader));
return this;
}
public centerTabStop(position: number): Paragraph {
this.properties.push(new CenterTabStop(position));
public centerTabStop(position: number, leader?: LeaderType): Paragraph {
this.properties.push(new CenterTabStop(position, leader));
return this;
}
@ -232,7 +232,12 @@ export class Paragraph extends XmlComponent {
return this;
}
public get Properties(): ParagraphProperties {
return this.properties;
public getStyles(): Style[] {
return this.properties.getStyles();
}
public addTabStop(run: Run): Paragraph {
this.root.splice(1, 0, run);
return this;
}
}

View File

@ -1,6 +1,7 @@
// http://officeopenxml.com/WPparagraphProperties.php
import { XmlComponent } from "file/xml-components";
import { Border } from "./formatting/border";
import { Style } from "./formatting/style";
export class ParagraphProperties extends XmlComponent {
public paragraphBorder: Border;
@ -17,4 +18,8 @@ export class ParagraphProperties extends XmlComponent {
public push(item: XmlComponent): void {
this.root.push(item);
}
public getStyles(): Style[] {
return this.root.filter((child) => child instanceof Style) as Style[];
}
}