move indent.ts over to paragraph and add a #indent method
This commit is contained in:
@ -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,
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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}}]},
|
||||
],
|
||||
},
|
||||
]
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user