diff --git a/src/file/table-of-contents/table-of-contents.spec.ts b/src/file/table-of-contents/table-of-contents.spec.ts index 3ff1eab243..b725c8de92 100644 --- a/src/file/table-of-contents/table-of-contents.spec.ts +++ b/src/file/table-of-contents/table-of-contents.spec.ts @@ -9,39 +9,53 @@ const DEFAULT_TOC = { "w:pPr": [], }, { - "w:fldChar": [ + "w:r": [ { - _attr: { - "w:fldCharType": "begin", - }, + "w:rPr": [], + }, + { + "w:fldChar": [ + { + _attr: { + "w:fldCharType": "begin", + }, + }, + ], + }, + { + "w:instrText": [ + { + _attr: { + "xml:space": "preserve", + }, + }, + 'TOC \\n "1-6"', + ], + }, + { + "w:fldChar": [ + { + _attr: { + "w:fldCharType": "separate", + }, + }, + ], }, ], }, { - "w:fldChar": [ + "w:r": [ { - _attr: { - "w:fldCharType": "separate", - }, + "w:rPr": [], }, - ], - }, - { - "w:instrText": [ { - _attr: { - "xml:space": "preserve", - }, - }, - 'TOC \\n "1-6"', - ], - }, - { - "w:fldChar": [ - { - _attr: { - "w:fldCharType": "end", - }, + "w:fldChar": [ + { + _attr: { + "w:fldCharType": "end", + }, + }, + ], }, ], }, diff --git a/src/file/table-of-contents/table-of-contents.ts b/src/file/table-of-contents/table-of-contents.ts index 3f0f206e59..7c0acec7d6 100644 --- a/src/file/table-of-contents/table-of-contents.ts +++ b/src/file/table-of-contents/table-of-contents.ts @@ -1,5 +1,6 @@ // import { TableOfContentsProperties } from "./properties"; import { Paragraph } from "file/paragraph"; +import { Run } from "file/paragraph/run"; import { Begin, End, Separate } from "file/paragraph/run/field"; import { TableOfContentsInstruction } from "./instruction"; @@ -9,9 +10,14 @@ export class TableOfContents extends Paragraph { constructor(/*tocProperties?: TableOfContentsProperties*/) { super(); // this.tocProperties = tocProperties || new TableOfContentsProperties(); - this.root.push(new Begin()); - this.root.push(new Separate()); - this.root.push(new TableOfContentsInstruction()); - this.root.push(new End()); + const firstRun = new Run(); + firstRun.addChildElement(new Begin()); + firstRun.addChildElement(new TableOfContentsInstruction()); + firstRun.addChildElement(new Separate()); + this.root.push(firstRun); + + const secondRun = new Run(); + secondRun.addChildElement(new End()); + this.root.push(secondRun); } }