add #font method to Run
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import { RunFonts } from "./run-fonts";
|
||||
import {RunProperties} from "./properties";
|
||||
import {Bold, Italics} from "./formatting";
|
||||
import {Tab} from "./tab";
|
||||
@ -11,7 +12,6 @@ import {Underline} from "./underline"
|
||||
export class Run extends XmlComponent {
|
||||
private properties: RunProperties;
|
||||
|
||||
|
||||
constructor() {
|
||||
super("w:r");
|
||||
this.properties = new RunProperties();
|
||||
@ -72,4 +72,9 @@ export class Run extends XmlComponent {
|
||||
this.properties.push(new SuperScript());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
font(fontName: string): Run {
|
||||
this.properties.push(new RunFonts(fontName));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { assert } from "chai";
|
||||
import { assert, expect } from "chai";
|
||||
import { Run } from "../../../docx/run";
|
||||
import { TextRun } from "../../../docx/run/text-run";
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
@ -85,4 +85,20 @@ describe("Run", () => {
|
||||
assert.equal(newJson.root[1].rootKey, "w:tab");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#font()", () => {
|
||||
it("should allow chaining calls", () => {
|
||||
expect(run.font("Times")).to.equal(run);
|
||||
});
|
||||
|
||||
it("should set the font as named", () => {
|
||||
run.font("Times");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user