diff --git a/src/file/file.ts b/src/file/file.ts index 429ec5d9be..484f69bd2d 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -288,6 +288,7 @@ export class File { } public generateTablesOfContents(): void { + // console.log("generateTablesOfContents"); this.document.getTablesOfContents().forEach((child) => this.generateContent(child)); } @@ -301,9 +302,10 @@ export class File { private generateContentForHeaderRange(toc: TableOfContents): void { const headerRange = toc.getHeaderRange(); const hyphenIndex = headerRange.indexOf("-"); + // console.log("Hyphen Index: ", hyphenIndex); if (hyphenIndex !== -1) { - const rangeBegin = parseInt(headerRange.substring(0, hyphenIndex), 2); - const rangeEnd = parseInt(headerRange.substring(hyphenIndex + 1), 2); + const rangeBegin = parseInt(headerRange.substring(0, hyphenIndex), 10); + const rangeEnd = parseInt(headerRange.substring(hyphenIndex + 1), 10); const styles = new Array(); for (let i = rangeBegin; i <= rangeEnd; i++) { styles.push(`Heading${i}`); @@ -327,7 +329,7 @@ export class File { // console.log("Generating content for paragraph: ", bookmarkId); const generatedParagraph = cloneDeep(paragraph); - generatedParagraph.rightTabStop(9016, "dot"); + generatedParagraph.clearPageBreaks().rightTabStop(9016, "dot"); const tabRun = new Run(); tabRun.addChildElement(new Tab()); diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index c08d168fe8..2de547bb7a 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -240,4 +240,10 @@ export class Paragraph extends XmlComponent { this.root.splice(1, 0, run); return this; } + + public clearPageBreaks(): Paragraph { + this.root = this.root.filter((child) => !(child instanceof PageBreak)); + this.properties.clearPageBreaks(); + return this; + } } diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index fa0dd971ff..53ae637835 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -1,6 +1,7 @@ // http://officeopenxml.com/WPparagraphProperties.php import { XmlComponent } from "file/xml-components"; import { Border } from "./formatting/border"; +import { PageBreakBefore } from "./formatting/page-break"; import { Style } from "./formatting/style"; export class ParagraphProperties extends XmlComponent { @@ -22,4 +23,9 @@ export class ParagraphProperties extends XmlComponent { public getStyles(): Style[] { return this.root.filter((child) => child instanceof Style) as Style[]; } + + public clearPageBreaks(): ParagraphProperties { + this.root = this.root.filter((child) => !(child instanceof PageBreakBefore)); + return this; + } }