diff --git a/demo/17-footnotes.ts b/demo/17-footnotes.ts index 3920d0dce8..bf3f11eb91 100644 --- a/demo/17-footnotes.ts +++ b/demo/17-footnotes.ts @@ -1,14 +1,20 @@ // Footnotes // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Packer, Paragraph } from "../build"; +import { Document, Packer, Paragraph, TextRun } from "../build"; const doc = new Document(); doc.addSection({ - children: [new Paragraph("Hello World").referenceFootnote(1), new Paragraph("Hello World").referenceFootnote(2)], + children: [ + new Paragraph({ + children: [new TextRun("Hello").referenceFootnote(1), new TextRun(" World!").referenceFootnote(2)], + }), + new Paragraph("Hello World").referenceFootnote(3), + ], }); +doc.createFootnote(new Paragraph("Foo")); doc.createFootnote(new Paragraph("Test")); doc.createFootnote(new Paragraph("My amazing reference")); diff --git a/src/file/paragraph/run/text-run.ts b/src/file/paragraph/run/text-run.ts index eeacf2dfd5..2bbf1bae75 100644 --- a/src/file/paragraph/run/text-run.ts +++ b/src/file/paragraph/run/text-run.ts @@ -1,3 +1,4 @@ +import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { IRunOptions, Run } from "./run"; import { Text } from "./run-components/text"; @@ -16,4 +17,9 @@ export class TextRun extends Run { super(options); this.root.push(new Text(options.text)); } + + public referenceFootnote(id: number): TextRun { + this.root.push(new FootnoteReferenceRun(id)); + return this; + } }