diff --git a/ts/docx/paragraph/index.ts b/ts/docx/paragraph/index.ts index c2b3c5ef37..b2fe66db93 100644 --- a/ts/docx/paragraph/index.ts +++ b/ts/docx/paragraph/index.ts @@ -38,6 +38,12 @@ export class Paragraph extends XmlComponent { return this; } + public createRun(text: string): TextRun { + const run = new TextRun(text); + this.addText(run); + return run; + } + public heading1(): Paragraph { this.properties.push(new Style("Heading1")); return this; diff --git a/ts/tests/docx/paragraph/paragraphTests.ts b/ts/tests/docx/paragraph/paragraphTests.ts index 4866246361..b58819dbb7 100644 --- a/ts/tests/docx/paragraph/paragraphTests.ts +++ b/ts/tests/docx/paragraph/paragraphTests.ts @@ -32,6 +32,20 @@ describe("Paragraph", () => { }); }); + describe("#createRun", () => { + it("should add a new run to the paragraph and return it", () => { + const run = paragraph.createRun("this is a test run"); + expect(run).to.be.instanceof(docx.TextRun); + const tree = new Formatter().format(paragraph)["w:p"]; + expect(tree).to.be.an("array").which.includes({ + "w:r": [ + {"w:rPr": []}, + {"w:t": ["this is a test run"]}, + ], + }); + }); + }); + describe("#heading1()", () => { it("should add heading style to JSON", () => { paragraph.heading1();