Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
cc9dff6b94 | |||
101cc0fdea | |||
d408262fa8 | |||
ed53c30f42 | |||
ebbf6a99c1 | |||
b98c103e45 | |||
518fec0595 | |||
659936f3f0 | |||
b0febf5054 | |||
56b951a2b1 | |||
a3a9958a69 | |||
4f36bbf426 | |||
357bc7f377 | |||
da8405b5b9 | |||
492face7ab | |||
b6351f0260 | |||
3a7f9053b9 | |||
19b122684c | |||
72e89cfc3c |
@ -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"
|
||||||
|
@ -66,6 +66,10 @@ exporter.pack('My First Document');
|
|||||||
## Examples
|
## Examples
|
||||||
Check [the Wiki](https://github.com/dolanmiu/docx/wiki/Examples) for examples.
|
Check [the Wiki](https://github.com/dolanmiu/docx/wiki/Examples) for examples.
|
||||||
|
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
Read the contribution guidelines [here](https://github.com/dolanmiu/docx/wiki/Contributing-Guidelines).
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Made with 💖
|
Made with 💖
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "2.1.3",
|
"version": "3.0.1",
|
||||||
"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": {
|
||||||
@ -22,6 +22,7 @@
|
|||||||
"url": "git+https://github.com/dolanmiu/docx.git"
|
"url": "git+https://github.com/dolanmiu/docx.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"docx",
|
||||||
"office",
|
"office",
|
||||||
"word",
|
"word",
|
||||||
"generate",
|
"generate",
|
||||||
|
@ -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;
|
12
ts/docx/document/body/body.ts
Normal file
12
ts/docx/document/body/body.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { XmlComponent } from "../../xml-components";
|
||||||
|
|
||||||
|
export class Body extends XmlComponent {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super("w:body");
|
||||||
|
}
|
||||||
|
|
||||||
|
public push(component: XmlComponent): void {
|
||||||
|
this.root.push(component);
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1 @@
|
|||||||
import { XmlComponent } from "../../xml-components";
|
export * from "./body";
|
||||||
|
|
||||||
export class Body extends XmlComponent {
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super("w:body");
|
|
||||||
}
|
|
||||||
|
|
||||||
public push(component: XmlComponent): void {
|
|
||||||
this.root.push(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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;
|
56
ts/docx/document/document.ts
Normal file
56
ts/docx/document/document.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// http://officeopenxml.com/WPdocument.php
|
||||||
|
import { Paragraph } from "../paragraph";
|
||||||
|
import { Table } from "../table";
|
||||||
|
import { XmlComponent } from "../xml-components";
|
||||||
|
import { Body } from "./body";
|
||||||
|
import { DocumentAttributes } from "./document-attributes";
|
||||||
|
|
||||||
|
export class Document extends XmlComponent {
|
||||||
|
private body: Body;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super("w:document");
|
||||||
|
this.root.push(new DocumentAttributes({
|
||||||
|
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
||||||
|
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
||||||
|
o: "urn:schemas-microsoft-com:office:office",
|
||||||
|
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
||||||
|
m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
|
||||||
|
v: "urn:schemas-microsoft-com:vml",
|
||||||
|
wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
|
||||||
|
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
||||||
|
w10: "urn:schemas-microsoft-com:office:word",
|
||||||
|
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
||||||
|
w14: "http://schemas.microsoft.com/office/word/2010/wordml",
|
||||||
|
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
|
||||||
|
wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
|
||||||
|
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
||||||
|
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
|
||||||
|
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
|
||||||
|
Ignorable: "w14 w15 wp14",
|
||||||
|
}));
|
||||||
|
this.body = new Body();
|
||||||
|
this.root.push(this.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addParagraph(paragraph: Paragraph): void {
|
||||||
|
this.body.push(paragraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
public createParagraph(text?: string): Paragraph {
|
||||||
|
const para = new Paragraph(text);
|
||||||
|
this.addParagraph(para);
|
||||||
|
return para;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addTable(table: Table): void {
|
||||||
|
this.body.push(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public createTable(rows: number, cols: number): Table {
|
||||||
|
const table = new Table(rows, cols);
|
||||||
|
this.addTable(table);
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,55 +1 @@
|
|||||||
import { Paragraph } from "../paragraph";
|
export * from "./document";
|
||||||
import { Table } from "../table";
|
|
||||||
import { XmlComponent } from "../xml-components";
|
|
||||||
import { Body } from "./body";
|
|
||||||
import { DocumentAttributes } from "./document-attributes";
|
|
||||||
|
|
||||||
export class Document extends XmlComponent {
|
|
||||||
private body: Body;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super("w:document");
|
|
||||||
this.root.push(new DocumentAttributes({
|
|
||||||
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
|
|
||||||
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
||||||
o: "urn:schemas-microsoft-com:office:office",
|
|
||||||
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
||||||
m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
|
|
||||||
v: "urn:schemas-microsoft-com:vml",
|
|
||||||
wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
|
|
||||||
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
|
||||||
w10: "urn:schemas-microsoft-com:office:word",
|
|
||||||
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
||||||
w14: "http://schemas.microsoft.com/office/word/2010/wordml",
|
|
||||||
w15: "http://schemas.microsoft.com/office/word/2012/wordml",
|
|
||||||
wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
|
|
||||||
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
|
|
||||||
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
|
|
||||||
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
|
|
||||||
Ignorable: "w14 w15 wp14",
|
|
||||||
}));
|
|
||||||
this.body = new Body();
|
|
||||||
this.root.push(this.body);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addParagraph(paragraph: Paragraph): void {
|
|
||||||
this.body.push(paragraph);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParagraph(text?: string): Paragraph {
|
|
||||||
const para = new Paragraph(text);
|
|
||||||
this.addParagraph(para);
|
|
||||||
return para;
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTable(table: Table): void {
|
|
||||||
this.body.push(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTable(rows: number, cols: number): Table {
|
|
||||||
const table = new Table(rows, cols);
|
|
||||||
this.addTable(table);
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
export { Document } from "./document";
|
export * from "./document";
|
||||||
export * from "./paragraph";
|
export * from "./paragraph";
|
||||||
export { Run } from "./run";
|
export * from "./run";
|
||||||
export { TextRun } from "./run/text-run";
|
|
||||||
export { PictureRun } from "./run/picture-run";
|
|
||||||
export { Table } from "./table";
|
export { Table } from "./table";
|
||||||
// Perhaps all run related stuff can be exported from run, instead of exporting Run, TextRun, PictureRun seperately.
|
|
||||||
|
@ -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,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,156 +1,2 @@
|
|||||||
import { IData } from "../../media/data";
|
|
||||||
import { Num } from "../../numbering/num";
|
|
||||||
import { Run } from "../run";
|
|
||||||
import { PictureRun } from "../run/picture-run";
|
|
||||||
import { TextRun } from "../run/text-run";
|
|
||||||
import { XmlComponent } from "../xml-components";
|
|
||||||
|
|
||||||
import { Alignment } from "./alignment";
|
|
||||||
import { ThematicBreak } from "./border";
|
|
||||||
import { Indent } from "./indent";
|
|
||||||
import { KeepLines, KeepNext } from "./keep";
|
|
||||||
import { PageBreak } from "./page-break";
|
|
||||||
import { ParagraphProperties } from "./properties";
|
|
||||||
import { ISpacingProperties, Spacing } from "./spacing";
|
|
||||||
import { Style } from "./style";
|
|
||||||
import { LeftTabStop, MaxRightTabStop } from "./tab-stop";
|
|
||||||
import { NumberProperties } from "./unordered-list";
|
|
||||||
|
|
||||||
export * from "./formatting";
|
export * from "./formatting";
|
||||||
|
export * from "./paragraph";
|
||||||
export class Paragraph extends XmlComponent {
|
|
||||||
private properties: ParagraphProperties;
|
|
||||||
|
|
||||||
constructor(text?: string) {
|
|
||||||
super("w:p");
|
|
||||||
this.properties = new ParagraphProperties();
|
|
||||||
this.root.push(this.properties);
|
|
||||||
if (text !== undefined) {
|
|
||||||
this.root.push(new TextRun(text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public addRun(run: Run): Paragraph {
|
|
||||||
this.root.push(run);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTextRun(text: string): TextRun {
|
|
||||||
const run = new TextRun(text);
|
|
||||||
this.addRun(run);
|
|
||||||
return run;
|
|
||||||
}
|
|
||||||
|
|
||||||
public createPictureRun(imageData: IData): PictureRun {
|
|
||||||
const run = new PictureRun(imageData);
|
|
||||||
this.addRun(run);
|
|
||||||
return run;
|
|
||||||
}
|
|
||||||
|
|
||||||
public heading1(): Paragraph {
|
|
||||||
this.properties.push(new Style("Heading1"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public heading2(): Paragraph {
|
|
||||||
this.properties.push(new Style("Heading2"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public heading3(): Paragraph {
|
|
||||||
this.properties.push(new Style("Heading3"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public heading4(): Paragraph {
|
|
||||||
this.properties.push(new Style("Heading4"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public heading5(): Paragraph {
|
|
||||||
this.properties.push(new Style("Heading5"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public title(): Paragraph {
|
|
||||||
this.properties.push(new Style("Title"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public center(): Paragraph {
|
|
||||||
this.properties.push(new Alignment("center"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public left(): Paragraph {
|
|
||||||
this.properties.push(new Alignment("left"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public right(): Paragraph {
|
|
||||||
this.properties.push(new Alignment("right"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public justified(): Paragraph {
|
|
||||||
this.properties.push(new Alignment("both"));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public thematicBreak(): Paragraph {
|
|
||||||
this.properties.push(new ThematicBreak());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public pageBreak(): Paragraph {
|
|
||||||
this.root.push(new PageBreak());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public maxRightTabStop(): Paragraph {
|
|
||||||
this.properties.push(new MaxRightTabStop());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public leftTabStop(position: number): Paragraph {
|
|
||||||
this.properties.push(new LeftTabStop(position));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bullet(): Paragraph {
|
|
||||||
this.properties.push(new Style("ListParagraph"));
|
|
||||||
this.properties.push(new NumberProperties(1, 0));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
|
|
||||||
this.properties.push(new Style("ListParagraph"));
|
|
||||||
this.properties.push(new NumberProperties(numbering.id, indentLevel));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public style(styleId: string): Paragraph {
|
|
||||||
this.properties.push(new Style(styleId));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public indent(start: number, hanging?: number): Paragraph {
|
|
||||||
this.properties.push(new Indent(start, hanging));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public spacing(params: ISpacingProperties): Paragraph {
|
|
||||||
this.properties.push(new Spacing(params));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public keepNext(): Paragraph {
|
|
||||||
this.properties.push(new KeepNext());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public keepLines(): Paragraph {
|
|
||||||
this.properties.push(new KeepLines());
|
|
||||||
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;
|
||||||
@ -145,7 +146,7 @@ describe("Paragraph", () => {
|
|||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:p": [{
|
"w:p": [{
|
||||||
"w:pPr": [],
|
"w:pPr": [],
|
||||||
},{
|
}, {
|
||||||
"w:r": [
|
"w:r": [
|
||||||
{"w:rPr": []},
|
{"w:rPr": []},
|
||||||
{"w:br": [{_attr: {"w:type": "page"}}]},
|
{"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": [
|
165
ts/docx/paragraph/paragraph.ts
Normal file
165
ts/docx/paragraph/paragraph.ts
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
// http://officeopenxml.com/WPparagraph.php
|
||||||
|
import { IData } from "../../media/data";
|
||||||
|
import { Num } from "../../numbering/num";
|
||||||
|
import { Run } from "../run";
|
||||||
|
import { PictureRun } from "../run/picture-run";
|
||||||
|
import { TextRun } from "../run/text-run";
|
||||||
|
import { XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
|
import { Alignment } from "./alignment";
|
||||||
|
import { ThematicBreak } from "./border";
|
||||||
|
import { Indent } from "./indent";
|
||||||
|
import { KeepLines, KeepNext } from "./keep";
|
||||||
|
import { PageBreak } from "./page-break";
|
||||||
|
import { ParagraphProperties } from "./properties";
|
||||||
|
import { ISpacingProperties, Spacing } from "./spacing";
|
||||||
|
import { Style } from "./style";
|
||||||
|
import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./tab-stop";
|
||||||
|
import { NumberProperties } from "./unordered-list";
|
||||||
|
|
||||||
|
export class Paragraph extends XmlComponent {
|
||||||
|
private properties: ParagraphProperties;
|
||||||
|
|
||||||
|
constructor(text?: string) {
|
||||||
|
super("w:p");
|
||||||
|
this.properties = new ParagraphProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
if (text !== undefined) {
|
||||||
|
this.root.push(new TextRun(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public addRun(run: Run): Paragraph {
|
||||||
|
this.root.push(run);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public createTextRun(text: string): TextRun {
|
||||||
|
const run = new TextRun(text);
|
||||||
|
this.addRun(run);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
|
public createPictureRun(imageData: IData): PictureRun {
|
||||||
|
const run = new PictureRun(imageData);
|
||||||
|
this.addRun(run);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
|
public heading1(): Paragraph {
|
||||||
|
this.properties.push(new Style("Heading1"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public heading2(): Paragraph {
|
||||||
|
this.properties.push(new Style("Heading2"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public heading3(): Paragraph {
|
||||||
|
this.properties.push(new Style("Heading3"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public heading4(): Paragraph {
|
||||||
|
this.properties.push(new Style("Heading4"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public heading5(): Paragraph {
|
||||||
|
this.properties.push(new Style("Heading5"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public title(): Paragraph {
|
||||||
|
this.properties.push(new Style("Title"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public center(): Paragraph {
|
||||||
|
this.properties.push(new Alignment("center"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public left(): Paragraph {
|
||||||
|
this.properties.push(new Alignment("left"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public right(): Paragraph {
|
||||||
|
this.properties.push(new Alignment("right"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public justified(): Paragraph {
|
||||||
|
this.properties.push(new Alignment("both"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public thematicBreak(): Paragraph {
|
||||||
|
this.properties.push(new ThematicBreak());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public pageBreak(): Paragraph {
|
||||||
|
this.root.push(new PageBreak());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public maxRightTabStop(): Paragraph {
|
||||||
|
this.properties.push(new MaxRightTabStop());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public leftTabStop(position: number): Paragraph {
|
||||||
|
this.properties.push(new LeftTabStop(position));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public rightTabStop(position: number): Paragraph {
|
||||||
|
this.properties.push(new RightTabStop(position));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public centerTabStop(position: number): Paragraph {
|
||||||
|
this.properties.push(new CenterTabStop(position));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bullet(): Paragraph {
|
||||||
|
this.properties.push(new Style("ListParagraph"));
|
||||||
|
this.properties.push(new NumberProperties(1, 0));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setNumbering(numbering: Num, indentLevel: number): Paragraph {
|
||||||
|
this.properties.push(new Style("ListParagraph"));
|
||||||
|
this.properties.push(new NumberProperties(numbering.id, indentLevel));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public style(styleId: string): Paragraph {
|
||||||
|
this.properties.push(new Style(styleId));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public indent(attrs: object): Paragraph {
|
||||||
|
this.properties.push(new Indent(attrs));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public spacing(params: ISpacingProperties): Paragraph {
|
||||||
|
this.properties.push(new Spacing(params));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public keepNext(): Paragraph {
|
||||||
|
this.properties.push(new KeepNext());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public keepLines(): Paragraph {
|
||||||
|
this.properties.push(new KeepLines());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -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,3 +1,4 @@
|
|||||||
|
// http://officeopenxml.com/WPtab.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
export class TabStop extends XmlComponent {
|
export class TabStop extends XmlComponent {
|
||||||
@ -8,15 +9,15 @@ export class TabStop extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TabOptions = "left" | "right";
|
export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start";
|
||||||
|
|
||||||
export class TabAttributes extends XmlAttributeComponent<{val: TabOptions, pos: string | number}> {
|
export class TabAttributes extends XmlAttributeComponent<{val: TabValue, pos: string | number}> {
|
||||||
protected xmlKeys = {val: "w:val", pos: "w:pos"};
|
protected xmlKeys = {val: "w:val", pos: "w:pos"};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Tab extends XmlComponent {
|
export class Tab extends XmlComponent {
|
||||||
|
|
||||||
constructor(value: TabOptions, position: string | number) {
|
constructor(value: TabValue, position: string | number) {
|
||||||
super("w:tab");
|
super("w:tab");
|
||||||
this.root.push(new TabAttributes({
|
this.root.push(new TabAttributes({
|
||||||
val: value,
|
val: value,
|
||||||
@ -36,3 +37,15 @@ export class LeftTabStop extends TabStop {
|
|||||||
super(new Tab("left", position));
|
super(new Tab("left", position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class RightTabStop extends TabStop {
|
||||||
|
constructor(position: number) {
|
||||||
|
super(new Tab("right", position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CenterTabStop extends TabStop {
|
||||||
|
constructor(position: number) {
|
||||||
|
super(new Tab("center", position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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,3 +0,0 @@
|
|||||||
export class Row {
|
|
||||||
|
|
||||||
}
|
|
@ -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,96 +1,3 @@
|
|||||||
import { Break } from "./break";
|
export * from "./run";
|
||||||
import { Caps, SmallCaps } from "./caps";
|
export * from "./text-run";
|
||||||
import { Bold, Color, DoubleStrike, Italics, Size, Strike } from "./formatting";
|
export * from "./picture-run";
|
||||||
import { RunProperties } from "./properties";
|
|
||||||
import { RunFonts } from "./run-fonts";
|
|
||||||
import { SubScript, SuperScript } from "./script";
|
|
||||||
import { Style } from "./style";
|
|
||||||
import { Tab } from "./tab";
|
|
||||||
import { Underline } from "./underline";
|
|
||||||
|
|
||||||
import { XmlComponent } from "../xml-components";
|
|
||||||
|
|
||||||
export class Run extends XmlComponent {
|
|
||||||
private properties: RunProperties;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super("w:r");
|
|
||||||
this.properties = new RunProperties();
|
|
||||||
this.root.push(this.properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bold(): Run {
|
|
||||||
this.properties.push(new Bold());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public italic(): Run {
|
|
||||||
this.properties.push(new Italics());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public underline(underlineType?: string, color?: string): Run {
|
|
||||||
this.properties.push(new Underline(underlineType, color));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public color(color: string): Run {
|
|
||||||
this.properties.push(new Color(color));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public size(size: number): Run {
|
|
||||||
this.properties.push(new Size(size));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public break(): Run {
|
|
||||||
this.root.splice(1, 0, new Break());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public tab(): Run {
|
|
||||||
this.root.splice(1, 0, new Tab());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public smallCaps(): Run {
|
|
||||||
this.properties.push(new SmallCaps());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public allCaps(): Run {
|
|
||||||
this.properties.push(new Caps());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public strike(): Run {
|
|
||||||
this.properties.push(new Strike());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public doubleStrike(): Run {
|
|
||||||
this.properties.push(new DoubleStrike());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public subScript(): Run {
|
|
||||||
this.properties.push(new SubScript());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public superScript(): Run {
|
|
||||||
this.properties.push(new SuperScript());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public font(fontName: string): Run {
|
|
||||||
this.properties.push(new RunFonts(fontName));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public style(styleId: string): Run {
|
|
||||||
this.properties.push(new Style(styleId));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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;
|
97
ts/docx/run/run.ts
Normal file
97
ts/docx/run/run.ts
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
// http://officeopenxml.com/WPtext.php
|
||||||
|
import { Break } from "./break";
|
||||||
|
import { Caps, SmallCaps } from "./caps";
|
||||||
|
import { Bold, Color, DoubleStrike, Italics, Size, Strike } from "./formatting";
|
||||||
|
import { RunProperties } from "./properties";
|
||||||
|
import { RunFonts } from "./run-fonts";
|
||||||
|
import { SubScript, SuperScript } from "./script";
|
||||||
|
import { Style } from "./style";
|
||||||
|
import { Tab } from "./tab";
|
||||||
|
import { Underline } from "./underline";
|
||||||
|
|
||||||
|
import { XmlComponent } from "../xml-components";
|
||||||
|
|
||||||
|
export class Run extends XmlComponent {
|
||||||
|
private properties: RunProperties;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super("w:r");
|
||||||
|
this.properties = new RunProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bold(): Run {
|
||||||
|
this.properties.push(new Bold());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public italic(): Run {
|
||||||
|
this.properties.push(new Italics());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public underline(underlineType?: string, color?: string): Run {
|
||||||
|
this.properties.push(new Underline(underlineType, color));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public color(color: string): Run {
|
||||||
|
this.properties.push(new Color(color));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public size(size: number): Run {
|
||||||
|
this.properties.push(new Size(size));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public break(): Run {
|
||||||
|
this.root.splice(1, 0, new Break());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public tab(): Run {
|
||||||
|
this.root.splice(1, 0, new Tab());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public smallCaps(): Run {
|
||||||
|
this.properties.push(new SmallCaps());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public allCaps(): Run {
|
||||||
|
this.properties.push(new Caps());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public strike(): Run {
|
||||||
|
this.properties.push(new Strike());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public doubleStrike(): Run {
|
||||||
|
this.properties.push(new DoubleStrike());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public subScript(): Run {
|
||||||
|
this.properties.push(new SubScript());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public superScript(): Run {
|
||||||
|
this.properties.push(new SuperScript());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public font(fontName: string): Run {
|
||||||
|
this.properties.push(new RunFonts(fontName));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public style(styleId: string): Run {
|
||||||
|
this.properties.push(new Style(styleId));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -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,123 +1 @@
|
|||||||
import { Paragraph } from "../paragraph";
|
export * from "./table";
|
||||||
import { XmlComponent } from "../xml-components";
|
|
||||||
import { IXmlableObject } from "../xml-components/xmlable-object";
|
|
||||||
import { TableGrid } from "./grid";
|
|
||||||
import { TableProperties, WidthTypes } from "./properties";
|
|
||||||
|
|
||||||
export class Table extends XmlComponent {
|
|
||||||
private properties: TableProperties;
|
|
||||||
private rows: TableRow[];
|
|
||||||
private grid: TableGrid;
|
|
||||||
|
|
||||||
constructor(rows: number, cols: number) {
|
|
||||||
super("w:tbl");
|
|
||||||
this.properties = new TableProperties();
|
|
||||||
this.root.push(this.properties);
|
|
||||||
|
|
||||||
const gridCols: number[] = [];
|
|
||||||
for (let i = 0; i < cols; i++) {
|
|
||||||
/*
|
|
||||||
0-width columns don't get rendered correctly, so we need
|
|
||||||
to give them some value. A reasonable default would be
|
|
||||||
~6in / numCols, but if we do that it becomes very hard
|
|
||||||
to resize the table using setWidth, unless the layout
|
|
||||||
algorithm is set to 'fixed'. Instead, the approach here
|
|
||||||
means even in 'auto' layout, setting a width on the
|
|
||||||
table will make it look reasonable, as the layout
|
|
||||||
algorithm will expand columns to fit its content
|
|
||||||
*/
|
|
||||||
gridCols.push(1);
|
|
||||||
}
|
|
||||||
this.grid = new TableGrid(gridCols);
|
|
||||||
this.root.push(this.grid);
|
|
||||||
|
|
||||||
this.rows = [];
|
|
||||||
for (let i = 0; i < rows; i++) {
|
|
||||||
const cells: TableCell[] = [];
|
|
||||||
for (let j = 0; j < cols; j++) {
|
|
||||||
cells.push(new TableCell());
|
|
||||||
}
|
|
||||||
const row = new TableRow(cells);
|
|
||||||
this.rows.push(row);
|
|
||||||
this.root.push(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getRow(ix: number): TableRow {
|
|
||||||
return this.rows[ix];
|
|
||||||
}
|
|
||||||
|
|
||||||
public getCell(row: number, col: number): TableCell {
|
|
||||||
return this.getRow(row).getCell(col);
|
|
||||||
}
|
|
||||||
|
|
||||||
public setWidth(type: WidthTypes, width: number | string): Table {
|
|
||||||
this.properties.setWidth(type, width);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public fixedWidthLayout(): Table {
|
|
||||||
this.properties.fixedWidthLayout();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableRow extends XmlComponent {
|
|
||||||
private properties: TableRowProperties;
|
|
||||||
private cells: TableCell[];
|
|
||||||
|
|
||||||
constructor(cells: TableCell[]) {
|
|
||||||
super("w:tr");
|
|
||||||
this.properties = new TableRowProperties();
|
|
||||||
this.root.push(this.properties);
|
|
||||||
this.cells = cells;
|
|
||||||
cells.forEach((c) => this.root.push(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
public getCell(ix: number): TableCell {
|
|
||||||
return this.cells[ix];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableRowProperties extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:trPr");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableCell extends XmlComponent {
|
|
||||||
private properties: TableCellProperties;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super("w:tc");
|
|
||||||
this.properties = new TableCellProperties();
|
|
||||||
this.root.push(this.properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addContent(content: Paragraph | Table): TableCell {
|
|
||||||
this.root.push(content);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public prepForXml(): IXmlableObject {
|
|
||||||
// Cells must end with a paragraph
|
|
||||||
const retval = super.prepForXml();
|
|
||||||
const content = retval["w:tc"];
|
|
||||||
if (!content[content.length - 1]["w:p"]) {
|
|
||||||
content.push(new Paragraph().prepForXml());
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParagraph(text?: string): Paragraph {
|
|
||||||
const para = new Paragraph(text);
|
|
||||||
this.addContent(para);
|
|
||||||
return para;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableCellProperties extends XmlComponent {
|
|
||||||
constructor() {
|
|
||||||
super("w:tcPr");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -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", () => {
|
123
ts/docx/table/table.ts
Normal file
123
ts/docx/table/table.ts
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
import { Paragraph } from "../paragraph";
|
||||||
|
import { XmlComponent } from "../xml-components";
|
||||||
|
import { IXmlableObject } from "../xml-components/xmlable-object";
|
||||||
|
import { TableGrid } from "./grid";
|
||||||
|
import { TableProperties, WidthTypes } from "./properties";
|
||||||
|
|
||||||
|
export class Table extends XmlComponent {
|
||||||
|
private properties: TableProperties;
|
||||||
|
private rows: TableRow[];
|
||||||
|
private grid: TableGrid;
|
||||||
|
|
||||||
|
constructor(rows: number, cols: number) {
|
||||||
|
super("w:tbl");
|
||||||
|
this.properties = new TableProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
|
||||||
|
const gridCols: number[] = [];
|
||||||
|
for (let i = 0; i < cols; i++) {
|
||||||
|
/*
|
||||||
|
0-width columns don't get rendered correctly, so we need
|
||||||
|
to give them some value. A reasonable default would be
|
||||||
|
~6in / numCols, but if we do that it becomes very hard
|
||||||
|
to resize the table using setWidth, unless the layout
|
||||||
|
algorithm is set to 'fixed'. Instead, the approach here
|
||||||
|
means even in 'auto' layout, setting a width on the
|
||||||
|
table will make it look reasonable, as the layout
|
||||||
|
algorithm will expand columns to fit its content
|
||||||
|
*/
|
||||||
|
gridCols.push(1);
|
||||||
|
}
|
||||||
|
this.grid = new TableGrid(gridCols);
|
||||||
|
this.root.push(this.grid);
|
||||||
|
|
||||||
|
this.rows = [];
|
||||||
|
for (let i = 0; i < rows; i++) {
|
||||||
|
const cells: TableCell[] = [];
|
||||||
|
for (let j = 0; j < cols; j++) {
|
||||||
|
cells.push(new TableCell());
|
||||||
|
}
|
||||||
|
const row = new TableRow(cells);
|
||||||
|
this.rows.push(row);
|
||||||
|
this.root.push(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getRow(ix: number): TableRow {
|
||||||
|
return this.rows[ix];
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCell(row: number, col: number): TableCell {
|
||||||
|
return this.getRow(row).getCell(col);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setWidth(type: WidthTypes, width: number | string): Table {
|
||||||
|
this.properties.setWidth(type, width);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public fixedWidthLayout(): Table {
|
||||||
|
this.properties.fixedWidthLayout();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableRow extends XmlComponent {
|
||||||
|
private properties: TableRowProperties;
|
||||||
|
private cells: TableCell[];
|
||||||
|
|
||||||
|
constructor(cells: TableCell[]) {
|
||||||
|
super("w:tr");
|
||||||
|
this.properties = new TableRowProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
this.cells = cells;
|
||||||
|
cells.forEach((c) => this.root.push(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCell(ix: number): TableCell {
|
||||||
|
return this.cells[ix];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableRowProperties extends XmlComponent {
|
||||||
|
constructor() {
|
||||||
|
super("w:trPr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableCell extends XmlComponent {
|
||||||
|
private properties: TableCellProperties;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super("w:tc");
|
||||||
|
this.properties = new TableCellProperties();
|
||||||
|
this.root.push(this.properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addContent(content: Paragraph | Table): TableCell {
|
||||||
|
this.root.push(content);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public prepForXml(): IXmlableObject {
|
||||||
|
// Cells must end with a paragraph
|
||||||
|
const retval = super.prepForXml();
|
||||||
|
const content = retval["w:tc"];
|
||||||
|
if (!content[content.length - 1]["w:p"]) {
|
||||||
|
content.push(new Paragraph().prepForXml());
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public createParagraph(text?: string): Paragraph {
|
||||||
|
const para = new Paragraph(text);
|
||||||
|
this.addContent(para);
|
||||||
|
return para;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableCellProperties extends XmlComponent {
|
||||||
|
constructor() {
|
||||||
|
super("w:tcPr");
|
||||||
|
}
|
||||||
|
}
|
@ -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,27 +1,3 @@
|
|||||||
import { BaseXmlComponent } from "./base";
|
export * from "./xml-component";
|
||||||
import { IXmlableObject } from "./xmlable-object";
|
|
||||||
export { BaseXmlComponent };
|
|
||||||
|
|
||||||
export abstract class XmlComponent extends BaseXmlComponent {
|
|
||||||
protected root: Array<BaseXmlComponent | string>;
|
|
||||||
|
|
||||||
constructor(rootKey: string) {
|
|
||||||
super(rootKey);
|
|
||||||
this.root = new Array<BaseXmlComponent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public prepForXml(): IXmlableObject {
|
|
||||||
const children = this.root.map((comp) => {
|
|
||||||
if (comp instanceof BaseXmlComponent) {
|
|
||||||
return comp.prepForXml();
|
|
||||||
}
|
|
||||||
return comp;
|
|
||||||
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
|
|
||||||
return {
|
|
||||||
[this.rootKey]: children,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export * from "./attributes";
|
export * from "./attributes";
|
||||||
export * from "./default-attributes";
|
export * from "./default-attributes";
|
||||||
|
@ -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 {
|
||||||
|
|
24
ts/docx/xml-components/xml-component.ts
Normal file
24
ts/docx/xml-components/xml-component.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { BaseXmlComponent } from "./base";
|
||||||
|
import { IXmlableObject } from "./xmlable-object";
|
||||||
|
export { BaseXmlComponent };
|
||||||
|
|
||||||
|
export abstract class XmlComponent extends BaseXmlComponent {
|
||||||
|
protected root: Array<BaseXmlComponent | string>;
|
||||||
|
|
||||||
|
constructor(rootKey: string) {
|
||||||
|
super(rootKey);
|
||||||
|
this.root = new Array<BaseXmlComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public prepForXml(): IXmlableObject {
|
||||||
|
const children = this.root.map((comp) => {
|
||||||
|
if (comp instanceof BaseXmlComponent) {
|
||||||
|
return comp.prepForXml();
|
||||||
|
}
|
||||||
|
return comp;
|
||||||
|
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
|
||||||
|
return {
|
||||||
|
[this.rootKey]: children,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
@ -1,3 +1,3 @@
|
|||||||
export { LocalPacker } from "./packer/local";
|
export * from "./packer/local";
|
||||||
export { ExpressPacker } from "./packer/express";
|
export * from "./packer/express";
|
||||||
export { Packer } from "./packer/packer";
|
export * from "./packer/packer";
|
||||||
|
@ -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,7 +1,7 @@
|
|||||||
import { RunProperties } from "../../docx/run/properties";
|
|
||||||
import { XmlComponent } from "../../docx/xml-components";
|
|
||||||
import { RunFonts } from "../../docx/run/run-fonts";
|
|
||||||
import { Size } from "../../docx/run/formatting";
|
import { Size } from "../../docx/run/formatting";
|
||||||
|
import { RunProperties } from "../../docx/run/properties";
|
||||||
|
import { RunFonts } from "../../docx/run/run-fonts";
|
||||||
|
import { XmlComponent } from "../../docx/xml-components";
|
||||||
|
|
||||||
export class RunPropertiesDefaults extends XmlComponent {
|
export class RunPropertiesDefaults extends XmlComponent {
|
||||||
private properties: RunProperties;
|
private properties: RunProperties;
|
||||||
|
@ -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,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
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 { ParagraphStyle } from "./style";
|
|
||||||
import { DocumentDefaults } from "./defaults";
|
import { DocumentDefaults } from "./defaults";
|
||||||
|
import { ParagraphStyle } from "./style";
|
||||||
|
|
||||||
export class Styles extends XmlComponent {
|
export class Styles extends XmlComponent {
|
||||||
|
|
||||||
|
@ -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,17 +0,0 @@
|
|||||||
/* tslint:disable */
|
|
||||||
import { assert } from "chai";
|
|
||||||
import { Utility } from "./utility";
|
|
||||||
/* tslint:enable */
|
|
||||||
|
|
||||||
describe("", () => {
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
// TODO
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("#methodName()", () => {
|
|
||||||
it("should ", () => {
|
|
||||||
// TODO
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -12,6 +12,8 @@
|
|||||||
"declaration": true
|
"declaration": true
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"tests"
|
"tests",
|
||||||
|
"**/*.spec.ts",
|
||||||
|
"**/_*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user