add paragraph#style method to quickly set the style

This commit is contained in:
felipe
2017-03-09 09:46:12 +01:00
parent f5144e6d72
commit 18ca93e50a
3 changed files with 23 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
interface IndentAttributesProperties {
left: number;

View File

@ -119,6 +119,11 @@ export class Paragraph extends XmlComponent {
return this;
}
public style(styleId: string): Paragraph {
this.properties.push(new Style(styleId));
return this;
}
public indent(start: number, hanging?: number): Paragraph {
this.properties.push(new Indent(start, hanging));
return this;

View File

@ -155,6 +155,23 @@ describe("Paragraph", () => {
});
});
describe("#style", () => {
it("should set the paragraph style to the given styleId", () => {
paragraph.style('myFancyStyle');
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"_attr": {}},
{"w:pStyle": [{"_attr": {"w:val": "myFancyStyle"}}]},
],
},
]
})
});
});
describe("#indent", () => {
it("should set the paragraph indent to the given values", () => {
paragraph.indent(720);