Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
492face7ab | |||
b6351f0260 | |||
3a7f9053b9 | |||
19b122684c | |||
72e89cfc3c | |||
5ae02c3342 | |||
258adba94c | |||
190208d5df | |||
32cda4dfb3 | |||
b2c3dd2f7b | |||
58eca3ff5b | |||
d5c04f9042 | |||
67ea7c95de | |||
e57fd8fc57 | |||
411c0dadb5 | |||
ee81f3c502 | |||
8263b93c36 | |||
be709d082c |
@ -4,6 +4,7 @@ node_js:
|
|||||||
install:
|
install:
|
||||||
- npm install
|
- npm install
|
||||||
script:
|
script:
|
||||||
|
- npm run lint
|
||||||
- npm test
|
- npm test
|
||||||
after_failure:
|
after_failure:
|
||||||
- "cat /home/travis/builds/dolanmiu/docx/npm-debug.log"
|
- "cat /home/travis/builds/dolanmiu/docx/npm-debug.log"
|
||||||
|
35
demo/demo3.js
Normal file
35
demo/demo3.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
const docx = require('../build');
|
||||||
|
|
||||||
|
var doc = new docx.Document();
|
||||||
|
|
||||||
|
const numbering = new docx.Numbering();
|
||||||
|
|
||||||
|
const abstractNum = numbering.createAbstractNumbering();
|
||||||
|
abstractNum.createLevel(0, "upperRoman", "%1", "start")
|
||||||
|
.addParagraphProperty(new docx.Indent(720, 260));
|
||||||
|
abstractNum.createLevel(1, "decimal", "%2.", "start")
|
||||||
|
.addParagraphProperty(new docx.Indent(1440, 980));
|
||||||
|
abstractNum.createLevel(2, "lowerLetter", "%3)", "start")
|
||||||
|
.addParagraphProperty(new docx.Indent(2160, 1700));
|
||||||
|
|
||||||
|
const concrete = numbering.createConcreteNumbering(abstractNum);
|
||||||
|
|
||||||
|
var topLevelP = new docx.Paragraph("Hey you");
|
||||||
|
var subP = new docx.Paragraph("What's up fam");
|
||||||
|
var secondSubP = new docx.Paragraph("Hello World 2");
|
||||||
|
var subSubP = new docx.Paragraph("Yeah boi");
|
||||||
|
|
||||||
|
topLevelP.setNumbering(concrete, 0);
|
||||||
|
subP.setNumbering(concrete, 1);
|
||||||
|
secondSubP.setNumbering(concrete, 1);
|
||||||
|
subSubP.setNumbering(concrete, 2);
|
||||||
|
|
||||||
|
doc.addParagraph(topLevelP);
|
||||||
|
doc.addParagraph(subP);
|
||||||
|
doc.addParagraph(secondSubP);
|
||||||
|
doc.addParagraph(subSubP);
|
||||||
|
|
||||||
|
var exporter = new docx.LocalPacker(doc);
|
||||||
|
exporter.pack('My Document');
|
||||||
|
|
||||||
|
console.log('Document created succesfully at project root!');
|
12
demo/demo4.js
Normal file
12
demo/demo4.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
const docx = require('../build');
|
||||||
|
|
||||||
|
var doc = new docx.Document();
|
||||||
|
|
||||||
|
const table = doc.createTable(4, 4);
|
||||||
|
table.getCell(2, 2).addContent(new docx.Paragraph('Hello'));
|
||||||
|
|
||||||
|
|
||||||
|
var exporter = new docx.LocalPacker(doc);
|
||||||
|
exporter.pack('My Document');
|
||||||
|
|
||||||
|
console.log('Document created succesfully at project root!');
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "2.1.1",
|
"version": "3.0.0",
|
||||||
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
"description": "Generate .docx documents with JavaScript (formerly Office-Clippy)",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -55,6 +55,6 @@
|
|||||||
"shelljs": "^0.7.7",
|
"shelljs": "^0.7.7",
|
||||||
"tslint": "^5.1.0",
|
"tslint": "^5.1.0",
|
||||||
"typedoc": "^0.5.10",
|
"typedoc": "^0.5.10",
|
||||||
"typescript": "^2.4.1"
|
"typescript": "2.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { Body } from "../../../docx/document/body";
|
|
||||||
import { Columns } from "../../../docx/document/body/columns";
|
import { Utility } from "../../../tests/utility";
|
||||||
import { DocumentGrid } from "../../../docx/document/body/doc-grid";
|
import { Body } from "./";
|
||||||
import { PageMargin } from "../../../docx/document/body/page-margin";
|
import { Columns } from "./columns";
|
||||||
import { PageSize } from "../../../docx/document/body/page-size";
|
import { DocumentGrid } from "./doc-grid";
|
||||||
import { SectionProperties } from "../../../docx/document/body/section-properties";
|
import { PageMargin } from "./page-margin";
|
||||||
import { Utility } from "../../utility";
|
import { PageSize } from "./page-size";
|
||||||
|
import { SectionProperties } from "./section-properties";
|
||||||
|
|
||||||
describe("Body", () => {
|
describe("Body", () => {
|
||||||
let body: Body;
|
let body: Body;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import * as docx from "../../../docx";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import * as docx from "../../";
|
||||||
|
import { Formatter } from "../../export/formatter";
|
||||||
|
|
||||||
describe("Document", () => {
|
describe("Document", () => {
|
||||||
let document: docx.Document;
|
let document: docx.Document;
|
@ -1,5 +1,5 @@
|
|||||||
export { Document } from "./document";
|
export { Document } from "./document";
|
||||||
export { Paragraph } from "./paragraph";
|
export * from "./paragraph";
|
||||||
export { Run } from "./run";
|
export { Run } from "./run";
|
||||||
export { TextRun } from "./run/text-run";
|
export { TextRun } from "./run/text-run";
|
||||||
export { PictureRun } from "./run/picture-run";
|
export { PictureRun } from "./run/picture-run";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { ThematicBreak } from "../../../docx/paragraph/border";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { ThematicBreak } from "./border";
|
||||||
|
|
||||||
describe("Border", () => {
|
describe("Border", () => {
|
||||||
// TODO: Need tests here
|
// TODO: Need tests here
|
@ -3,22 +3,25 @@ import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
|||||||
interface IIndentAttributesProperties {
|
interface IIndentAttributesProperties {
|
||||||
left?: number;
|
left?: number;
|
||||||
hanging?: number;
|
hanging?: number;
|
||||||
|
firstLine?: number;
|
||||||
|
start?: number;
|
||||||
|
end?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
|
class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties> {
|
||||||
protected xmlKeys = {
|
protected xmlKeys = {
|
||||||
left: "w:left",
|
left: "w:left",
|
||||||
hanging: "w:hanging",
|
hanging: "w:hanging",
|
||||||
|
firstLine: "w:firstLine",
|
||||||
|
start: "w:start",
|
||||||
|
end: "w:end",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Indent extends XmlComponent {
|
export class Indent extends XmlComponent {
|
||||||
|
|
||||||
constructor(left: number, hanging?: number) {
|
constructor(attrs: object) {
|
||||||
super("w:ind");
|
super("w:ind");
|
||||||
this.root.push(new IndentAttributes({
|
this.root.push(new IndentAttributes(attrs));
|
||||||
left: left,
|
|
||||||
hanging: hanging,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ import { Style } from "./style";
|
|||||||
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
||||||
import { NumberProperties } from "./unordered-list";
|
import { NumberProperties } from "./unordered-list";
|
||||||
|
|
||||||
|
export * from "./formatting";
|
||||||
|
|
||||||
export class Paragraph extends XmlComponent {
|
export class Paragraph extends XmlComponent {
|
||||||
private properties: ParagraphProperties;
|
private properties: ParagraphProperties;
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ export class Paragraph extends XmlComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public pageBreak(): Paragraph {
|
public pageBreak(): Paragraph {
|
||||||
this.properties.push(new PageBreak());
|
this.root.push(new PageBreak());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +134,8 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public indent(start: number, hanging?: number): Paragraph {
|
public indent(attrs: object): Paragraph {
|
||||||
this.properties.push(new Indent(start, hanging));
|
this.properties.push(new Indent(attrs));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { PageBreak } from "../../../docx/paragraph/page-break";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { PageBreak } from "./page-break";
|
||||||
|
|
||||||
describe("PageBreak", () => {
|
describe("PageBreak", () => {
|
||||||
let pageBreak: PageBreak;
|
let pageBreak: PageBreak;
|
@ -1,7 +1,8 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import * as docx from "../../../docx";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import * as docx from "../../docx";
|
||||||
import { Numbering } from "../../../numbering";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { Numbering } from "../../numbering";
|
||||||
|
|
||||||
describe("Paragraph", () => {
|
describe("Paragraph", () => {
|
||||||
let paragraph: docx.Paragraph;
|
let paragraph: docx.Paragraph;
|
||||||
@ -144,12 +145,12 @@ describe("Paragraph", () => {
|
|||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [{
|
"w:p": [{
|
||||||
"w:pPr": [{
|
"w:pPr": [],
|
||||||
"w:r": [
|
}, {
|
||||||
{"w:rPr": []},
|
"w:r": [
|
||||||
{"w:br": [{_attr: {"w:type": "page"}}]},
|
{"w:rPr": []},
|
||||||
],
|
{"w:br": [{_attr: {"w:type": "page"}}]},
|
||||||
}],
|
],
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -240,7 +241,7 @@ describe("Paragraph", () => {
|
|||||||
|
|
||||||
describe("#indent", () => {
|
describe("#indent", () => {
|
||||||
it("should set the paragraph indent to the given values", () => {
|
it("should set the paragraph indent to the given values", () => {
|
||||||
paragraph.indent(720);
|
paragraph.indent({ left: 720 });
|
||||||
const tree = new Formatter().format(paragraph);
|
const tree = new Formatter().format(paragraph);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [
|
"w:p": [
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { Spacing } from "../../../docx/paragraph/spacing";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { Spacing } from "./spacing";
|
||||||
|
|
||||||
describe("Spacing", () => {
|
describe("Spacing", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { Style } from "../../../docx/paragraph/style";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { Style } from "./style";
|
||||||
|
|
||||||
describe("ParagraphStyle", () => {
|
describe("ParagraphStyle", () => {
|
||||||
let style: Style;
|
let style: Style;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { LeftTabStop, MaxRightTabStop } from "../../../docx/paragraph/tab-stop";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
||||||
|
|
||||||
describe("LeftTabStop", () => {
|
describe("LeftTabStop", () => {
|
||||||
let tabStop: LeftTabStop;
|
let tabStop: LeftTabStop;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { NumberProperties } from "../../../docx/paragraph/unordered-list";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { NumberProperties } from "./unordered-list";
|
||||||
|
|
||||||
describe("NumberProperties", () => {
|
describe("NumberProperties", () => {
|
||||||
let numberProperties: NumberProperties;
|
let numberProperties: NumberProperties;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { Break } from "../../../docx/run/break";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { Break } from "./break";
|
||||||
|
|
||||||
describe("Break", () => {
|
describe("Break", () => {
|
||||||
let currentBreak: Break;
|
let currentBreak: Break;
|
@ -1,7 +1,8 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Drawing } from "../../../../docx/run/run-components/drawing";
|
|
||||||
import { Utility } from "../../../utility";
|
import { Utility } from "../../../../tests/utility";
|
||||||
|
import { Drawing } from "./";
|
||||||
|
|
||||||
describe("Drawing", () => {
|
describe("Drawing", () => {
|
||||||
let currentBreak: Drawing;
|
let currentBreak: Drawing;
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { Text } from "../../../../docx/run/run-components/text";
|
|
||||||
import { Formatter } from "../../../../export/formatter";
|
import { Formatter } from "../../../export/formatter";
|
||||||
|
import { Text } from "./text";
|
||||||
|
|
||||||
describe("Text", () => {
|
describe("Text", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { RunFonts } from "../../../docx/run/run-fonts";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { RunFonts } from "./run-fonts";
|
||||||
|
|
||||||
describe("RunFonts", () => {
|
describe("RunFonts", () => {
|
||||||
|
|
@ -1,7 +1,8 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import { Run } from "../../../docx/run";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { Run } from "./";
|
||||||
|
|
||||||
describe("Run", () => {
|
describe("Run", () => {
|
||||||
let run: Run;
|
let run: Run;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { SubScript, SuperScript } from "../../../docx/run/script";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { SubScript, SuperScript } from "./script";
|
||||||
|
|
||||||
describe("SubScript", () => {
|
describe("SubScript", () => {
|
||||||
let subScript: SubScript;
|
let subScript: SubScript;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { DoubleStrike, Strike } from "../../../docx/run/formatting";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { DoubleStrike, Strike } from "./formatting";
|
||||||
|
|
||||||
describe("Strike", () => {
|
describe("Strike", () => {
|
||||||
let strike: Strike;
|
let strike: Strike;
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { Tab } from "../../../docx/run/tab";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { Tab } from "./tab";
|
||||||
|
|
||||||
describe("Tab", () => {
|
describe("Tab", () => {
|
||||||
let tab: Tab;
|
let tab: Tab;
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { TextRun } from "../../../docx/run/text-run";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { TextRun } from "./text-run";
|
||||||
|
|
||||||
describe("TextRun", () => {
|
describe("TextRun", () => {
|
||||||
let run: TextRun;
|
let run: TextRun;
|
@ -1,7 +1,8 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import * as u from "../../../docx/run/underline";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import * as u from "./underline";
|
||||||
|
|
||||||
describe("Underline", () => {
|
describe("Underline", () => {
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { GridCol, TableGrid } from "../../../docx/table/grid";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { GridCol, TableGrid } from "./grid";
|
||||||
|
|
||||||
describe("GridCol", () => {
|
describe("GridCol", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
@ -1,6 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { TableProperties } from "../../../docx/table/properties";
|
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
|
import { TableProperties } from "./properties";
|
||||||
|
|
||||||
describe("TableProperties", () => {
|
describe("TableProperties", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
@ -1,8 +1,9 @@
|
|||||||
/* tslint:disable:no-unused-expression */
|
/* tslint:disable:no-unused-expression */
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { Paragraph } from "../../../docx/paragraph";
|
|
||||||
import { Table } from "../../../docx/table";
|
import { Formatter } from "../../export/formatter";
|
||||||
import { Formatter } from "../../../export/formatter";
|
import { Paragraph } from "../paragraph";
|
||||||
|
import { Table } from "./";
|
||||||
|
|
||||||
describe("Table", () => {
|
describe("Table", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
@ -1,5 +1,6 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { Attributes } from "../../../docx/xml-components";
|
|
||||||
|
import { Attributes } from "./";
|
||||||
|
|
||||||
describe("Attribute", () => {
|
describe("Attribute", () => {
|
||||||
describe("#constructor()", () => {
|
describe("#constructor()", () => {
|
@ -1,6 +1,7 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { XmlComponent } from "../../../docx/xml-components";
|
|
||||||
import { Utility } from "../../utility";
|
import { Utility } from "../../tests/utility";
|
||||||
|
import { XmlComponent } from "./";
|
||||||
|
|
||||||
class TestComponent extends XmlComponent {
|
class TestComponent extends XmlComponent {
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
|
||||||
import * as docx from "../../docx";
|
import * as docx from "../docx";
|
||||||
import { Attributes } from "../../docx/xml-components";
|
import { Attributes } from "../docx/xml-components";
|
||||||
import { Formatter } from "../../export/formatter";
|
import { Formatter } from "../export/formatter";
|
||||||
import { Properties } from "../../properties";
|
import { Properties } from "../properties";
|
||||||
import { Utility } from "../utility";
|
import { Utility } from "../tests/utility";
|
||||||
|
|
||||||
describe("Formatter", () => {
|
describe("Formatter", () => {
|
||||||
let formatter: Formatter;
|
let formatter: Formatter;
|
@ -35,39 +35,39 @@ export class Numbering extends XmlComponent {
|
|||||||
const abstractNumbering = this.createAbstractNumbering();
|
const abstractNumbering = this.createAbstractNumbering();
|
||||||
|
|
||||||
abstractNumbering.createLevel(0, "bullet", "•", "left")
|
abstractNumbering.createLevel(0, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(720, 360))
|
.addParagraphProperty(new Indent({ left: 720, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(1, "bullet", "o", "left")
|
abstractNumbering.createLevel(1, "bullet", "o", "left")
|
||||||
.addParagraphProperty(new Indent(1440, 360))
|
.addParagraphProperty(new Indent({ left: 1440, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(2, "bullet", "•", "left")
|
abstractNumbering.createLevel(2, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(2160, 360))
|
.addParagraphProperty(new Indent({ left: 2160, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Wingdings", "default"));
|
.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(3, "bullet", "•", "left")
|
abstractNumbering.createLevel(3, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(2880, 360))
|
.addParagraphProperty(new Indent({ left: 2880, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(4, "bullet", "o", "left")
|
abstractNumbering.createLevel(4, "bullet", "o", "left")
|
||||||
.addParagraphProperty(new Indent(3600, 360))
|
.addParagraphProperty(new Indent({ left: 3600, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(5, "bullet", "•", "left")
|
abstractNumbering.createLevel(5, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(4320, 360))
|
.addParagraphProperty(new Indent({ left: 4320, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Wingdings", "default"));
|
.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(6, "bullet", "•", "left")
|
abstractNumbering.createLevel(6, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(5040, 360))
|
.addParagraphProperty(new Indent({ left: 5040, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Symbol", "default"));
|
.addRunProperty(new RunFonts("Symbol", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(7, "bullet", "o", "left")
|
abstractNumbering.createLevel(7, "bullet", "o", "left")
|
||||||
.addParagraphProperty(new Indent(5760, 360))
|
.addParagraphProperty(new Indent({ left: 5760, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Courier New", "default"));
|
.addRunProperty(new RunFonts("Courier New", "default"));
|
||||||
|
|
||||||
abstractNumbering.createLevel(8, "bullet", "•", "left")
|
abstractNumbering.createLevel(8, "bullet", "•", "left")
|
||||||
.addParagraphProperty(new Indent(6480, 360))
|
.addParagraphProperty(new Indent({ left: 6480, hanging: 360 }))
|
||||||
.addRunProperty(new RunFonts("Wingdings", "default"));
|
.addRunProperty(new RunFonts("Wingdings", "default"));
|
||||||
|
|
||||||
this.createConcreteNumbering(abstractNumbering);
|
this.createConcreteNumbering(abstractNumbering);
|
||||||
|
@ -196,8 +196,8 @@ export class LevelBase extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public indent(left: number, hanging?: number): Level {
|
public indent(attrs: object): Level {
|
||||||
this.addParagraphProperty(new paragraph.Indent(left, hanging));
|
this.addParagraphProperty(new paragraph.Indent(attrs));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "../export/formatter";
|
||||||
import { Numbering } from "../numbering";
|
import { Numbering } from "./";
|
||||||
import { AbstractNumbering } from "../numbering/abstract-numbering";
|
import { AbstractNumbering } from "./abstract-numbering";
|
||||||
import { LevelForOverride } from "../numbering/level";
|
import { LevelForOverride } from "./level";
|
||||||
import { Num } from "../numbering/num";
|
import { Num } from "./num";
|
||||||
|
|
||||||
describe("Numbering", () => {
|
describe("Numbering", () => {
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ describe("AbstractNumbering", () => {
|
|||||||
it("#indent", () => {
|
it("#indent", () => {
|
||||||
const abstractNumbering = new AbstractNumbering(1);
|
const abstractNumbering = new AbstractNumbering(1);
|
||||||
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.")
|
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.")
|
||||||
.indent(720);
|
.indent({ left: 720 });
|
||||||
const tree = new Formatter().format(level);
|
const tree = new Formatter().format(level);
|
||||||
expect(tree["w:lvl"]).to.include({
|
expect(tree["w:lvl"]).to.include({
|
||||||
"w:pPr": [{"w:ind": [{_attr: {"w:left": 720}}]}],
|
"w:pPr": [{"w:ind": [{_attr: {"w:left": 720}}]}],
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "../export/formatter";
|
||||||
import { Properties } from "../properties";
|
import { Properties } from "./";
|
||||||
|
|
||||||
describe("Properties", () => {
|
describe("Properties", () => {
|
||||||
|
|
@ -1,10 +1,24 @@
|
|||||||
|
import { Size } from "../../docx/run/formatting";
|
||||||
import { RunProperties } from "../../docx/run/properties";
|
import { RunProperties } from "../../docx/run/properties";
|
||||||
|
import { RunFonts } from "../../docx/run/run-fonts";
|
||||||
import { XmlComponent } from "../../docx/xml-components";
|
import { XmlComponent } from "../../docx/xml-components";
|
||||||
|
|
||||||
export class RunPropertiesDefaults extends XmlComponent {
|
export class RunPropertiesDefaults extends XmlComponent {
|
||||||
|
private properties: RunProperties;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super("w:rPrDefault");
|
super("w:rPrDefault");
|
||||||
this.root.push(new RunProperties());
|
this.properties = new RunProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public size(size: number): RunPropertiesDefaults {
|
||||||
|
this.properties.push(new Size(size));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public font(fontName: string): RunPropertiesDefaults {
|
||||||
|
this.properties.push(new RunFonts(fontName));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Color, Italics, Size } from "../docx/run/formatting";
|
import { Color, Italics, Size } from "../docx/run/formatting";
|
||||||
|
|
||||||
import { Styles } from "./";
|
import { Styles } from "./";
|
||||||
import { DocumentDefaults } from "./defaults";
|
// import { DocumentDefaults } from "./defaults";
|
||||||
import {
|
import {
|
||||||
Heading1Style, Heading2Style, Heading3Style, Heading4Style, Heading5Style, Heading6Style,
|
Heading1Style, Heading2Style, Heading3Style, Heading4Style, Heading5Style, Heading6Style,
|
||||||
ListParagraph, TitleStyle,
|
ListParagraph, TitleStyle,
|
||||||
@ -11,7 +11,7 @@ export class DefaultStylesFactory {
|
|||||||
|
|
||||||
public newInstance(): Styles {
|
public newInstance(): Styles {
|
||||||
const styles = new Styles();
|
const styles = new Styles();
|
||||||
styles.push(new DocumentDefaults());
|
styles.createDocumentDefaults();
|
||||||
|
|
||||||
const titleStyle = new TitleStyle();
|
const titleStyle = new TitleStyle();
|
||||||
titleStyle.addRunProperty(new Size(56));
|
titleStyle.addRunProperty(new Size(56));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { DocumentAttributes } from "../docx/document/document-attributes";
|
import { DocumentAttributes } from "../docx/document/document-attributes";
|
||||||
import { XmlComponent } from "../docx/xml-components";
|
import { XmlComponent } from "../docx/xml-components";
|
||||||
|
import { DocumentDefaults } from "./defaults";
|
||||||
import { ParagraphStyle } from "./style";
|
import { ParagraphStyle } from "./style";
|
||||||
|
|
||||||
export class Styles extends XmlComponent {
|
export class Styles extends XmlComponent {
|
||||||
@ -14,11 +15,7 @@ export class Styles extends XmlComponent {
|
|||||||
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
|
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
|
||||||
Ignorable: "w14 w15",
|
Ignorable: "w14 w15",
|
||||||
}));
|
}));
|
||||||
// let latentStyles = new LatentStyles();
|
|
||||||
// latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({
|
|
||||||
// name: "Normal"
|
|
||||||
// })));
|
|
||||||
// this.root.push(latentStyles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public push(style: XmlComponent): Styles {
|
public push(style: XmlComponent): Styles {
|
||||||
@ -26,6 +23,12 @@ export class Styles extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createDocumentDefaults(): DocumentDefaults {
|
||||||
|
const defaults = new DocumentDefaults();
|
||||||
|
this.push(defaults);
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
|
public createParagraphStyle(styleId: string, name?: string): ParagraphStyle {
|
||||||
const para = new ParagraphStyle(styleId, name);
|
const para = new ParagraphStyle(styleId, name);
|
||||||
this.push(para);
|
this.push(para);
|
||||||
|
@ -171,8 +171,8 @@ export class ParagraphStyle extends Style {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public indent(left: number, hanging?: number): ParagraphStyle {
|
public indent(attrs: object): ParagraphStyle {
|
||||||
this.addParagraphProperty(new paragraph.Indent(left, hanging));
|
this.addParagraphProperty(new paragraph.Indent(attrs));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { assert, expect } from "chai";
|
import { assert, expect } from "chai";
|
||||||
import { Formatter } from "../export/formatter";
|
import { Formatter } from "../export/formatter";
|
||||||
import { Styles } from "../styles";
|
import { Styles } from "./";
|
||||||
import { ParagraphStyle, Style } from "../styles/style";
|
import { ParagraphStyle, Style } from "./style";
|
||||||
import * as components from "../styles/style/components";
|
import * as components from "./style/components";
|
||||||
|
|
||||||
describe("Styles", () => {
|
describe("Styles", () => {
|
||||||
let styles: Styles;
|
let styles: Styles;
|
||||||
@ -185,7 +185,7 @@ describe("ParagraphStyle", () => {
|
|||||||
describe("formatting methods: paragraph properties", () => {
|
describe("formatting methods: paragraph properties", () => {
|
||||||
it("#indent", () => {
|
it("#indent", () => {
|
||||||
const style = new ParagraphStyle("myStyleId")
|
const style = new ParagraphStyle("myStyleId")
|
||||||
.indent(720);
|
.indent({ left: 720 });
|
||||||
const tree = new Formatter().format(style);
|
const tree = new Formatter().format(style);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:style": [
|
"w:style": [
|
@ -9,5 +9,9 @@
|
|||||||
"sourceRoot": "./",
|
"sourceRoot": "./",
|
||||||
"rootDir": "./",
|
"rootDir": "./",
|
||||||
"module": "commonjs"
|
"module": "commonjs"
|
||||||
}
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.spec.ts",
|
||||||
|
"**/*.d.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* tslint:disable */
|
/* tslint:disable */
|
||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
|
|
||||||
import { Utility } from "./utility";
|
import { Utility } from "./utility";
|
||||||
/* tslint:enable */
|
/* tslint:enable */
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
"declaration": true
|
"declaration": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"tests"
|
"tests",
|
||||||
|
"**/*.spec.ts",
|
||||||
|
"**/_*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user