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 {
|
export class Indent extends XmlComponent {
|
||||||
|
|
||||||
constructor(left: number, hanging: number) {
|
constructor(left: number, hanging?: number) {
|
||||||
super("w:ind");
|
super("w:ind");
|
||||||
this.root.push(new IndentAttributes({
|
this.root.push(new IndentAttributes({
|
||||||
left: left,
|
left: left,
|
@ -1,7 +1,9 @@
|
|||||||
import { Num } from "../../numbering/num";
|
import { Num } from "../../numbering/num";
|
||||||
import { TextRun } from "../run/text-run";
|
import { TextRun } from "../run/text-run";
|
||||||
import { Attributes, XmlComponent } from "../xml-components";
|
import { Attributes, XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
import { ThematicBreak } from "./border";
|
import { ThematicBreak } from "./border";
|
||||||
|
import { Indent } from "./indent";
|
||||||
import { PageBreak } from "./page-break";
|
import { PageBreak } from "./page-break";
|
||||||
import { ParagraphProperties } from "./properties";
|
import { ParagraphProperties } from "./properties";
|
||||||
import { Style } from "./style";
|
import { Style } from "./style";
|
||||||
@ -116,4 +118,9 @@ export class Paragraph extends XmlComponent {
|
|||||||
this.properties.push(new NumberProperties(numbering.id, indentLevel));
|
this.properties.push(new NumberProperties(numbering.id, indentLevel));
|
||||||
return this;
|
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 * as _ from "lodash";
|
||||||
import { DocumentAttributes } from "../docx/document/document-attributes";
|
import { DocumentAttributes } from "../docx/document/document-attributes";
|
||||||
|
import { Indent } from "../docx/paragraph/indent";
|
||||||
import { RunFonts } from "../docx/run/run-fonts";
|
import { RunFonts } from "../docx/run/run-fonts";
|
||||||
import { MultiPropertyXmlComponent } from "../docx/xml-components";
|
import { MultiPropertyXmlComponent } from "../docx/xml-components";
|
||||||
import { AbstractNumbering } from "./abstract-numbering";
|
import { AbstractNumbering } from "./abstract-numbering";
|
||||||
import { Indent } from "./indent";
|
|
||||||
import { Level } from "./level";
|
import { Level } from "./level";
|
||||||
import { Num } from "./num";
|
import { Num } from "./num";
|
||||||
|
|
||||||
|
@ -136,7 +136,6 @@ describe("Paragraph", () => {
|
|||||||
|
|
||||||
paragraph.setNumbering(letterNumbering, 0);
|
paragraph.setNumbering(letterNumbering, 0);
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
console.log(JSON.stringify(tree, null, 2));
|
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"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