add an #underline method to ParagraphStyle

This commit is contained in:
felipe
2017-03-09 13:19:50 +01:00
parent 766bcabcb8
commit ac7799a875
2 changed files with 52 additions and 0 deletions

View File

@ -100,6 +100,11 @@ export class ParagraphStyle extends Style {
return this; return this;
} }
public underline(underlineType?: string, color?: string): ParagraphStyle {
this.addRunProperty(new formatting.Underline(underlineType, color));
return this;
}
public color(color: string): ParagraphStyle { public color(color: string): ParagraphStyle {
this.addRunProperty(new formatting.Color(color)); this.addRunProperty(new formatting.Color(color));
return this; return this;

View File

@ -235,6 +235,53 @@ describe("ParagraphStyle", () => {
}); });
}); });
describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => {
const style = new ParagraphStyle("myStyleId")
.underline();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]},
{"w:rPr": [
{"w:u": [{_attr: {"w:val": "single"}}]},
]},
],
});
});
it("should set the style if given", () => {
const style = new ParagraphStyle("myStyleId")
.underline("double");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]},
{"w:rPr": [
{"w:u": [{_attr: {"w:val": "double"}}]},
]},
],
});
});
it("should set the style and color if given", () => {
const style = new ParagraphStyle("myStyleId")
.underline("double", "005599");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": [{_attr: {}}]},
{"w:rPr": [
{"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]},
]},
],
});
});
});
it("#color", () => { it("#color", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId")
.color("123456"); .color("123456");