added #style method to runs
This commit is contained in:
@ -5,6 +5,7 @@ import { RunProperties } from "./properties";
|
|||||||
import { RunFonts } from "./run-fonts";
|
import { RunFonts } from "./run-fonts";
|
||||||
import { SubScript, SuperScript } from "./script";
|
import { SubScript, SuperScript } from "./script";
|
||||||
import { DoubleStrike, Strike } from "./strike";
|
import { DoubleStrike, Strike } from "./strike";
|
||||||
|
import { Style } from "./style";
|
||||||
import { Tab } from "./tab";
|
import { Tab } from "./tab";
|
||||||
import { Underline } from "./underline";
|
import { Underline } from "./underline";
|
||||||
|
|
||||||
@ -88,4 +89,9 @@ export class Run extends XmlComponent {
|
|||||||
this.properties.push(new RunFonts(fontName));
|
this.properties.push(new RunFonts(fontName));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public style(styleId: string): Run {
|
||||||
|
this.properties.push(new Style(styleId));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
13
ts/docx/run/style.ts
Normal file
13
ts/docx/run/style.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
|
class StyleAttributes extends XmlAttributeComponent<{val: string}> {
|
||||||
|
protected xmlKeys = {val: "w:val"};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Style extends XmlComponent {
|
||||||
|
|
||||||
|
constructor(styleId: string) {
|
||||||
|
super("w:rStyle");
|
||||||
|
this.root.push(new StyleAttributes({val: styleId}));
|
||||||
|
}
|
||||||
|
}
|
@ -141,4 +141,16 @@ describe("Run", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#style", () => {
|
||||||
|
it("should set the style to the given styleId", () => {
|
||||||
|
run.style("myRunStyle");
|
||||||
|
const tree = new Formatter().format(run);
|
||||||
|
expect(tree).to.deep.equal({
|
||||||
|
"w:r": [
|
||||||
|
{"w:rPr": [{"w:rStyle": [{_attr: {"w:val": "myRunStyle"}}]}]},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user