add #font method to Run
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import {XmlComponent, Attributes} from "../xml-components";
|
import {XmlComponent, Attributes} from "../xml-components";
|
||||||
|
import { RunFonts } from "./run-fonts";
|
||||||
import {RunProperties} from "./properties";
|
import {RunProperties} from "./properties";
|
||||||
import {Bold, Italics} from "./formatting";
|
import {Bold, Italics} from "./formatting";
|
||||||
import {Tab} from "./tab";
|
import {Tab} from "./tab";
|
||||||
@ -11,7 +12,6 @@ import {Underline} from "./underline"
|
|||||||
export class Run extends XmlComponent {
|
export class Run extends XmlComponent {
|
||||||
private properties: RunProperties;
|
private properties: RunProperties;
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:r");
|
super("w:r");
|
||||||
this.properties = new RunProperties();
|
this.properties = new RunProperties();
|
||||||
@ -72,4 +72,9 @@ export class Run extends XmlComponent {
|
|||||||
this.properties.push(new SuperScript());
|
this.properties.push(new SuperScript());
|
||||||
return this;
|
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 { Run } from "../../../docx/run";
|
||||||
import { TextRun } from "../../../docx/run/text-run";
|
import { TextRun } from "../../../docx/run/text-run";
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../../export/formatter";
|
||||||
@ -85,4 +85,20 @@ describe("Run", () => {
|
|||||||
assert.equal(newJson.root[1].rootKey, "w:tab");
|
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