add paragraph#style method to quickly set the style
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
interface IndentAttributesProperties {
|
interface IndentAttributesProperties {
|
||||||
left: number;
|
left: number;
|
||||||
|
@ -119,6 +119,11 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public style(styleId: string): Paragraph {
|
||||||
|
this.properties.push(new Style(styleId));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public indent(start: number, hanging?: number): Paragraph {
|
public indent(start: number, hanging?: number): Paragraph {
|
||||||
this.properties.push(new Indent(start, hanging));
|
this.properties.push(new Indent(start, hanging));
|
||||||
return this;
|
return this;
|
||||||
|
@ -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", () => {
|
describe("#indent", () => {
|
||||||
it("should set the paragraph indent to the given values", () => {
|
it("should set the paragraph indent to the given values", () => {
|
||||||
paragraph.indent(720);
|
paragraph.indent(720);
|
||||||
|
Reference in New Issue
Block a user