diff --git a/demo/demo10.js b/demo/demo10.js index aec22f3d53..1669d22180 100644 --- a/demo/demo10.js +++ b/demo/demo10.js @@ -311,4 +311,4 @@ const doc = documentCreator.create([experiences, education, skills, achievements var exporter = new docx.LocalPacker(doc); exporter.pack("Dolan Miu CV"); -console.log('Document created successfully at project root!'); +console.log('Document created successfully at project root!'); \ No newline at end of file diff --git a/demo/demo3.js b/demo/demo3.js index e31a1dce6f..accd597905 100644 --- a/demo/demo3.js +++ b/demo/demo3.js @@ -29,6 +29,16 @@ doc.addParagraph(subP); doc.addParagraph(secondSubP); doc.addParagraph(subSubP); +var bullet1 = new docx.Paragraph("Hey you").bullet(); +var bullet2 = new docx.Paragraph("What's up fam").bullet(1); +var bullet3 = new docx.Paragraph("Hello World 2").bullet(2); +var bullet4 = new docx.Paragraph("Yeah boi").bullet(3); + +doc.addParagraph(bullet1); +doc.addParagraph(bullet2); +doc.addParagraph(bullet3); +doc.addParagraph(bullet4); + var exporter = new docx.LocalPacker(doc); exporter.pack('My Document'); diff --git a/package.json b/package.json index 7bf374b153..a0db01f8e0 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "webpack": "rimraf ./build && webpack", "demo": "npm run build && node ./demo", "typedoc": "typedoc --out docs/ src/ --module commonjs --target ES6 --disableOutputCheck --excludePrivate --externalPattern \"**/*.spec.ts\"", - "style": "prettier -l \"src/**/*.ts\"", + "style": "prettier --debug-check \"src/**/*.ts\"", "fix-types": "node types-absolute-fixer.js" }, "files": [ diff --git a/src/file/numbering/numbering.ts b/src/file/numbering/numbering.ts index 64ec0b5a9c..e7cc5ac5a3 100644 --- a/src/file/numbering/numbering.ts +++ b/src/file/numbering/numbering.ts @@ -1,7 +1,6 @@ import { XmlComponent } from "file/xml-components"; import { DocumentAttributes } from "../document/document-attributes"; import { Indent } from "../paragraph/formatting"; -import { RunFonts } from "../paragraph/run/run-fonts"; import { AbstractNumbering } from "./abstract-numbering"; import { Num } from "./num"; @@ -37,49 +36,40 @@ export class Numbering extends XmlComponent { const abstractNumbering = this.createAbstractNumbering(); abstractNumbering - .createLevel(0, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 720, hanging: 360 })) - .addRunProperty(new RunFonts("Symbol", "default")); + .createLevel(0, "bullet", "\u25CF", "left") + .addParagraphProperty(new Indent({ left: 720, hanging: 360 })); abstractNumbering - .createLevel(1, "bullet", "o", "left") - .addParagraphProperty(new Indent({ left: 1440, hanging: 360 })) - .addRunProperty(new RunFonts("Courier New", "default")); + .createLevel(1, "bullet", "\u25CB", "left") + .addParagraphProperty(new Indent({ left: 1440, hanging: 360 })); abstractNumbering - .createLevel(2, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 2160, hanging: 360 })) - .addRunProperty(new RunFonts("Wingdings", "default")); + .createLevel(2, "bullet", "\u25A0", "left") + .addParagraphProperty(new Indent({ left: 2160, hanging: 360 })); abstractNumbering - .createLevel(3, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 2880, hanging: 360 })) - .addRunProperty(new RunFonts("Symbol", "default")); + .createLevel(3, "bullet", "\u25CF", "left") + .addParagraphProperty(new Indent({ left: 2880, hanging: 360 })); abstractNumbering - .createLevel(4, "bullet", "o", "left") - .addParagraphProperty(new Indent({ left: 3600, hanging: 360 })) - .addRunProperty(new RunFonts("Courier New", "default")); + .createLevel(4, "bullet", "\u25CB", "left") + .addParagraphProperty(new Indent({ left: 3600, hanging: 360 })); abstractNumbering - .createLevel(5, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 4320, hanging: 360 })) - .addRunProperty(new RunFonts("Wingdings", "default")); + .createLevel(5, "bullet", "\u25A0", "left") + .addParagraphProperty(new Indent({ left: 4320, hanging: 360 })); abstractNumbering - .createLevel(6, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 5040, hanging: 360 })) - .addRunProperty(new RunFonts("Symbol", "default")); + .createLevel(6, "bullet", "\u25CF", "left") + .addParagraphProperty(new Indent({ left: 5040, hanging: 360 })); abstractNumbering - .createLevel(7, "bullet", "o", "left") - .addParagraphProperty(new Indent({ left: 5760, hanging: 360 })) - .addRunProperty(new RunFonts("Courier New", "default")); + .createLevel(7, "bullet", "\u25CB", "left") + .addParagraphProperty(new Indent({ left: 5760, hanging: 360 })); abstractNumbering - .createLevel(8, "bullet", "•", "left") - .addParagraphProperty(new Indent({ left: 6480, hanging: 360 })) - .addRunProperty(new RunFonts("Wingdings", "default")); + .createLevel(8, "bullet", "\u25A0", "left") + .addParagraphProperty(new Indent({ left: 6480, hanging: 360 })); this.createConcreteNumbering(abstractNumbering); } diff --git a/src/file/paragraph/paragraph.spec.ts b/src/file/paragraph/paragraph.spec.ts index 54c5970679..e63f316049 100644 --- a/src/file/paragraph/paragraph.spec.ts +++ b/src/file/paragraph/paragraph.spec.ts @@ -163,7 +163,7 @@ describe("Paragraph", () => { describe("#bullet()", () => { it("should add list paragraph style to JSON", () => { - paragraph.bullet(); + paragraph.bullet(0); const tree = new Formatter().format(paragraph); expect(tree) .to.have.property("w:p") @@ -179,7 +179,7 @@ describe("Paragraph", () => { }); it("it should add numbered properties", () => { - paragraph.bullet(); + paragraph.bullet(1); const tree = new Formatter().format(paragraph); expect(tree) .to.have.property("w:p") @@ -190,7 +190,7 @@ describe("Paragraph", () => { .which.is.an("array") .which.has.length.at.least(2); expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({ - "w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 0 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }], + "w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 1 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }], }); }); }); diff --git a/src/file/paragraph/paragraph.ts b/src/file/paragraph/paragraph.ts index 9af203d7e7..e0ed98b84e 100644 --- a/src/file/paragraph/paragraph.ts +++ b/src/file/paragraph/paragraph.ts @@ -129,9 +129,10 @@ export class Paragraph extends XmlComponent { return this; } - public bullet(): Paragraph { + public bullet(indentLevel: number): Paragraph { + indentLevel = indentLevel || 0; this.properties.push(new Style("ListParagraph")); - this.properties.push(new NumberProperties(1, 0)); + this.properties.push(new NumberProperties(1, indentLevel)); return this; }