added #createParagraphStyle method to Styles
This commit is contained in:
@ -4,6 +4,7 @@ import { DocumentDefaults } from "./defaults";
|
||||
import { LatentStyles } from "./latent-styles";
|
||||
import { LatentStyleException } from "./latent-styles/exceptions";
|
||||
import { LatentStyleExceptionAttributes } from "./latent-styles/exceptions/attributes";
|
||||
import { ParagraphStyle } from "./style";
|
||||
|
||||
export class Styles extends XmlComponent {
|
||||
|
||||
@ -34,4 +35,10 @@ export class Styles extends XmlComponent {
|
||||
element.clearVariables();
|
||||
});
|
||||
}
|
||||
|
||||
public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
|
||||
const para = new ParagraphStyle(styleId, name);
|
||||
this.push(para);
|
||||
return para;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,33 @@ describe("Styles", () => {
|
||||
assert.equal(newJson.rootKey, "w:styles");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#createParagraphStyle", () => {
|
||||
it("should create a new paragraph style and push it onto this collection", () => {
|
||||
const ps = styles.createParagraphStyle("pStyleId");
|
||||
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
|
||||
expect(tree).to.deep.equal([{
|
||||
"w:style": [
|
||||
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
|
||||
{"w:pPr": [{_attr: {}}]},
|
||||
{"w:rPr": []},
|
||||
],
|
||||
}]);
|
||||
});
|
||||
|
||||
it("should set the paragraph name if given", () => {
|
||||
const ps = styles.createParagraphStyle("pStyleId", "Paragraph Style");
|
||||
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
|
||||
expect(tree).to.deep.equal([{
|
||||
"w:style": [
|
||||
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
|
||||
{"w:name": [{_attr: {"w:val": "Paragraph Style"}}]},
|
||||
{"w:pPr": [{_attr: {}}]},
|
||||
{"w:rPr": []},
|
||||
],
|
||||
}]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Style", () => {
|
||||
|
Reference in New Issue
Block a user