diff --git a/ts/numbering/indent.ts b/ts/docx/paragraph/indent.ts similarity index 91% rename from ts/numbering/indent.ts rename to ts/docx/paragraph/indent.ts index b5bdac02b0..24a73cb3e8 100644 --- a/ts/numbering/indent.ts +++ b/ts/docx/paragraph/indent.ts @@ -17,7 +17,7 @@ class IndentAttributes extends XmlAttributeComponent { export class Indent extends XmlComponent { - constructor(left: number, hanging: number) { + constructor(left: number, hanging?: number) { super("w:ind"); this.root.push(new IndentAttributes({ left: left, diff --git a/ts/docx/paragraph/index.ts b/ts/docx/paragraph/index.ts index 368cdc1f5a..e22badcba5 100644 --- a/ts/docx/paragraph/index.ts +++ b/ts/docx/paragraph/index.ts @@ -1,7 +1,9 @@ import { Num } from "../../numbering/num"; import { TextRun } from "../run/text-run"; import { Attributes, XmlComponent } from "../xml-components"; + import { ThematicBreak } from "./border"; +import { Indent } from "./indent"; import { PageBreak } from "./page-break"; import { ParagraphProperties } from "./properties"; import { Style } from "./style"; @@ -116,4 +118,9 @@ export class Paragraph extends XmlComponent { this.properties.push(new NumberProperties(numbering.id, indentLevel)); return this; } + + public indent(start: number, hanging?: number): Paragraph { + this.properties.push(new Indent(start, hanging)); + return this; + } } diff --git a/ts/numbering/index.ts b/ts/numbering/index.ts index 39bfda0867..828933ae90 100644 --- a/ts/numbering/index.ts +++ b/ts/numbering/index.ts @@ -1,9 +1,9 @@ import * as _ from "lodash"; import { DocumentAttributes } from "../docx/document/document-attributes"; +import { Indent } from "../docx/paragraph/indent"; import { RunFonts } from "../docx/run/run-fonts"; import { MultiPropertyXmlComponent } from "../docx/xml-components"; import { AbstractNumbering } from "./abstract-numbering"; -import { Indent } from "./indent"; import { Level } from "./level"; import { Num } from "./num"; diff --git a/ts/tests/docx/paragraph/paragraphTests.ts b/ts/tests/docx/paragraph/paragraphTests.ts index 81fb18564d..e581bf11f9 100644 --- a/ts/tests/docx/paragraph/paragraphTests.ts +++ b/ts/tests/docx/paragraph/paragraphTests.ts @@ -136,7 +136,6 @@ describe("Paragraph", () => { paragraph.setNumbering(letterNumbering, 0); const tree = new Formatter().format(paragraph); - console.log(JSON.stringify(tree, null, 2)); expect(tree).to.deep.equal({ "w:p": [ { @@ -155,4 +154,21 @@ describe("Paragraph", () => { }) }); }); + + describe("#indent", () => { + it("should set the paragraph indent to the given values", () => { + paragraph.indent(720); + const tree = new Formatter().format(paragraph); + expect(tree).to.deep.equal({ + "w:p": [ + { + "w:pPr": [ + {"_attr": {}}, + {"w:ind": [{"_attr": {"w:left": 720}}]}, + ], + }, + ] + }) + }); + }); });