add paragraph.createRun method

This commit is contained in:
felipe
2017-03-10 14:35:37 +01:00
parent ea647d84df
commit 8d11ec3422
2 changed files with 20 additions and 0 deletions

View File

@ -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;

View File

@ -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();