add paragraph.createRun method
This commit is contained in:
@ -38,6 +38,12 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createRun(text: string): TextRun {
|
||||||
|
const run = new TextRun(text);
|
||||||
|
this.addText(run);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
public heading1(): Paragraph {
|
public heading1(): Paragraph {
|
||||||
this.properties.push(new Style("Heading1"));
|
this.properties.push(new Style("Heading1"));
|
||||||
return this;
|
return this;
|
||||||
|
@ -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()", () => {
|
describe("#heading1()", () => {
|
||||||
it("should add heading style to JSON", () => {
|
it("should add heading style to JSON", () => {
|
||||||
paragraph.heading1();
|
paragraph.heading1();
|
||||||
|
Reference in New Issue
Block a user