Made project Prettier compliant

This commit is contained in:
Dolan
2018-01-23 01:33:12 +00:00
parent f2027230a0
commit e93d6799fd
101 changed files with 1198 additions and 1207 deletions

View File

@ -76,6 +76,5 @@ export class Compiler {
resolve(); resolve();
}); });
}); });
} }
} }

View File

@ -14,7 +14,10 @@ export class ExpressPacker implements IPacker {
this.res = res; this.res = res;
this.res.on("close", () => { this.res.on("close", () => {
return res.status(200).send("OK").end(); return res
.status(200)
.send("OK")
.end();
}); });
} }

View File

@ -24,7 +24,7 @@ describe("LocalPacker", () => {
}); });
describe("#pack()", () => { describe("#pack()", () => {
it("should create a standard docx file", async function () { it("should create a standard docx file", async function() {
this.timeout(99999999); this.timeout(99999999);
await packer.pack("build/tests/test"); await packer.pack("build/tests/test");
fs.statSync("build/tests/test.docx"); fs.statSync("build/tests/test.docx");
@ -32,7 +32,7 @@ describe("LocalPacker", () => {
}); });
describe("#packPdf", () => { describe("#packPdf", () => {
it("should create a standard PDF file", async function () { it("should create a standard PDF file", async function() {
this.timeout(99999999); this.timeout(99999999);
await packer.packPdf("build/tests/pdf-test"); await packer.packPdf("build/tests/pdf-test");

View File

@ -43,6 +43,5 @@ export class LocalPacker implements IPacker {
resolve(); resolve();
}); });
}); });
} }
} }

View File

@ -13,21 +13,22 @@ export class PdfConvertWrapper {
url: "http://mirror1.convertonlinefree.com", url: "http://mirror1.convertonlinefree.com",
encoding: null, encoding: null,
headers: { headers: {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36", "User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36",
}, },
formData: { formData: {
"__EVENTTARGET": "", __EVENTTARGET: "",
"__EVENTARGUMENT": "", __EVENTARGUMENT: "",
"__VIEWSTATE": "", __VIEWSTATE: "",
"ctl00$MainContent$fu": { ctl00$MainContent$fu: {
value: fs.readFileSync(filePath), value: fs.readFileSync(filePath),
options: { options: {
filename: "output.docx", filename: "output.docx",
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
}, },
}, },
"ctl00$MainContent$btnConvert": "Convert", ctl00$MainContent$btnConvert: "Convert",
"ctl00$MainContent$fuZip": "", ctl00$MainContent$fuZip: "",
}, },
}); });
} }

View File

@ -21,7 +21,6 @@ describe("Body", () => {
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create the Section Properties", () => { it("should create the Section Properties", () => {
const newJson = Utility.jsonify(body); const newJson = Utility.jsonify(body);
assert.equal(newJson.root[0].rootKey, "w:sectPr"); assert.equal(newJson.root[0].rootKey, "w:sectPr");

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class Body extends XmlComponent { export class Body extends XmlComponent {
constructor() { constructor() {
super("w:body"); super("w:body");
} }

View File

@ -1,11 +1,12 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class Columns extends XmlComponent { export class Columns extends XmlComponent {
constructor() { constructor() {
super("w:cols"); super("w:cols");
this.root.push(new Attributes({ this.root.push(
space: "708", new Attributes({
})); space: "708",
}),
);
} }
} }

View File

@ -1,11 +1,12 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class DocumentGrid extends XmlComponent { export class DocumentGrid extends XmlComponent {
constructor() { constructor() {
super("w:docGrid"); super("w:docGrid");
this.root.push(new Attributes({ this.root.push(
linePitch: "360", new Attributes({
})); linePitch: "360",
}),
);
} }
} }

View File

@ -1,17 +1,18 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class PageMargin extends XmlComponent { export class PageMargin extends XmlComponent {
constructor() { constructor() {
super("w:pgMar"); super("w:pgMar");
this.root.push(new Attributes({ this.root.push(
top: "1440", new Attributes({
right: "1440", top: "1440",
bottom: "1440", right: "1440",
left: "1440", bottom: "1440",
header: "708", left: "1440",
footer: "708", header: "708",
gutter: "0", footer: "708",
})); gutter: "0",
}),
);
} }
} }

View File

@ -1,12 +1,13 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class PageSize extends XmlComponent { export class PageSize extends XmlComponent {
constructor() { constructor() {
super("w:pgSz"); super("w:pgSz");
this.root.push(new Attributes({ this.root.push(
w: "11906", new Attributes({
h: "16838", w: "11906",
})); h: "16838",
}),
);
} }
} }

View File

@ -5,14 +5,15 @@ import { PageMargin } from "./page-margin";
import { PageSize } from "./page-size"; import { PageSize } from "./page-size";
export class SectionProperties extends XmlComponent { export class SectionProperties extends XmlComponent {
constructor() { constructor() {
super("w:sectPr"); super("w:sectPr");
this.root.push(new Attributes({ this.root.push(
rsidR: "00B64E8F", new Attributes({
rsidRPr: "00D842E4", rsidR: "00B64E8F",
rsidSect: "000A6AD0", rsidRPr: "00D842E4",
})); rsidSect: "000A6AD0",
}),
);
this.root.push(new PageSize()); this.root.push(new PageSize());
this.root.push(new PageMargin()); this.root.push(new PageMargin());
this.root.push(new Columns()); this.root.push(new Columns());

View File

@ -11,7 +11,6 @@ describe("Document", () => {
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create valid JSON", () => { it("should create valid JSON", () => {
const stringifiedJson = JSON.stringify(document); const stringifiedJson = JSON.stringify(document);
let newJson; let newJson;
@ -30,7 +29,9 @@ describe("Document", () => {
const para = document.createParagraph(); const para = document.createParagraph();
expect(para).to.be.an.instanceof(docx.Paragraph); expect(para).to.be.an.instanceof(docx.Paragraph);
const body = new Formatter().format(document)["w:document"][1]["w:body"]; const body = new Formatter().format(document)["w:document"][1]["w:body"];
expect(body).to.be.an("array").which.has.length.at.least(1); expect(body)
.to.be.an("array")
.which.has.length.at.least(1);
expect(body[0]).to.have.property("w:p"); expect(body[0]).to.have.property("w:p");
}); });
@ -38,13 +39,14 @@ describe("Document", () => {
const para = document.createParagraph("sample paragraph text"); const para = document.createParagraph("sample paragraph text");
expect(para).to.be.an.instanceof(docx.Paragraph); expect(para).to.be.an.instanceof(docx.Paragraph);
const body = new Formatter().format(document)["w:document"][1]["w:body"]; const body = new Formatter().format(document)["w:document"][1]["w:body"];
expect(body).to.be.an("array").which.has.length.at.least(1); expect(body)
expect(body[0]).to.have.property("w:p").which.includes({ .to.be.an("array")
"w:r": [ .which.has.length.at.least(1);
{"w:rPr": []}, expect(body[0])
{"w:t": [{_attr: {"xml:space": "preserve"}}, "sample paragraph text"]}, .to.have.property("w:p")
], .which.includes({
}); "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "sample paragraph text"] }],
});
}); });
}); });
@ -53,21 +55,27 @@ describe("Document", () => {
const table = document.createTable(2, 3); const table = document.createTable(2, 3);
expect(table).to.be.an.instanceof(docx.Table); expect(table).to.be.an.instanceof(docx.Table);
const body = new Formatter().format(document)["w:document"][1]["w:body"]; const body = new Formatter().format(document)["w:document"][1]["w:body"];
expect(body).to.be.an("array").which.has.length.at.least(1); expect(body)
.to.be.an("array")
.which.has.length.at.least(1);
expect(body[0]).to.have.property("w:tbl"); expect(body[0]).to.have.property("w:tbl");
}); });
it("should create a table with the correct dimensions", () => { it("should create a table with the correct dimensions", () => {
document.createTable(2, 3); document.createTable(2, 3);
const body = new Formatter().format(document)["w:document"][1]["w:body"]; const body = new Formatter().format(document)["w:document"][1]["w:body"];
expect(body).to.be.an("array").which.has.length.at.least(1); expect(body)
expect(body[0]).to.have.property("w:tbl").which.includes({ .to.be.an("array")
"w:tblGrid": [ .which.has.length.at.least(1);
{"w:gridCol": [{_attr: {"w:w": 1}}]}, expect(body[0])
{"w:gridCol": [{_attr: {"w:w": 1}}]}, .to.have.property("w:tbl")
{"w:gridCol": [{_attr: {"w:w": 1}}]}, .which.includes({
], "w:tblGrid": [
}); { "w:gridCol": [{ _attr: { "w:w": 1 } }] },
{ "w:gridCol": [{ _attr: { "w:w": 1 } }] },
{ "w:gridCol": [{ _attr: { "w:w": 1 } }] },
],
});
expect(body[0]["w:tbl"].filter((x) => x["w:tr"])).to.have.length(2); expect(body[0]["w:tbl"].filter((x) => x["w:tr"])).to.have.length(2);
}); });
}); });

View File

@ -11,25 +11,27 @@ export class Document extends XmlComponent {
constructor() { constructor() {
super("w:document"); super("w:document");
this.root.push(new DocumentAttributes({ this.root.push(
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", new DocumentAttributes({
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
o: "urn:schemas-microsoft-com:office:office", mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", o: "urn:schemas-microsoft-com:office:office",
m: "http://schemas.openxmlformats.org/officeDocument/2006/math", r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
v: "urn:schemas-microsoft-com:vml", m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", v: "urn:schemas-microsoft-com:vml",
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
w10: "urn:schemas-microsoft-com:office:word", wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", w10: "urn:schemas-microsoft-com:office:word",
w14: "http://schemas.microsoft.com/office/word/2010/wordml", w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
w15: "http://schemas.microsoft.com/office/word/2012/wordml", w14: "http://schemas.microsoft.com/office/word/2010/wordml",
wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", w15: "http://schemas.microsoft.com/office/word/2012/wordml",
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
wne: "http://schemas.microsoft.com/office/word/2006/wordml", wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", wne: "http://schemas.microsoft.com/office/word/2006/wordml",
Ignorable: "w14 w15 wp14", wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
})); Ignorable: "w14 w15 wp14",
}),
);
this.body = new Body(); this.body = new Body();
this.root.push(this.body); this.root.push(this.body);
} }

View File

@ -3,7 +3,6 @@ import { XmlComponent } from "file/xml-components";
import { Inline } from "./inline"; import { Inline } from "./inline";
export class Drawing extends XmlComponent { export class Drawing extends XmlComponent {
constructor(imageData: IMediaData) { constructor(imageData: IMediaData) {
super("w:drawing"); super("w:drawing");

View File

@ -2,14 +2,15 @@ import { XmlComponent } from "file/xml-components";
import { DocPropertiesAttributes } from "./doc-properties-attributes"; import { DocPropertiesAttributes } from "./doc-properties-attributes";
export class DocProperties extends XmlComponent { export class DocProperties extends XmlComponent {
constructor() { constructor() {
super("wp:docPr"); super("wp:docPr");
this.root.push(new DocPropertiesAttributes({ this.root.push(
id: 0, new DocPropertiesAttributes({
name: "", id: 0,
descr: "", name: "",
})); descr: "",
}),
);
} }
} }

View File

@ -2,15 +2,16 @@ import { XmlComponent } from "file/xml-components";
import { EffectExtentAttributes } from "./effect-extent-attributes"; import { EffectExtentAttributes } from "./effect-extent-attributes";
export class EffectExtent extends XmlComponent { export class EffectExtent extends XmlComponent {
constructor() { constructor() {
super("wp:effectExtent"); super("wp:effectExtent");
this.root.push(new EffectExtentAttributes({ this.root.push(
b: 0, new EffectExtentAttributes({
l: 0, b: 0,
r: 0, l: 0,
t: 0, r: 0,
})); t: 0,
}),
);
} }
} }

View File

@ -2,13 +2,14 @@ import { XmlComponent } from "file/xml-components";
import { ExtentAttributes } from "./extent-attributes"; import { ExtentAttributes } from "./extent-attributes";
export class Extent extends XmlComponent { export class Extent extends XmlComponent {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super("wp:extent"); super("wp:extent");
this.root.push(new ExtentAttributes({ this.root.push(
cx: x, new ExtentAttributes({
cy: y, cx: x,
})); cy: y,
}),
);
} }
} }

View File

@ -2,13 +2,14 @@ import { XmlComponent } from "file/xml-components";
import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes"; import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes";
export class GraphicFrameLocks extends XmlComponent { export class GraphicFrameLocks extends XmlComponent {
constructor() { constructor() {
super("a:graphicFrameLocks"); super("a:graphicFrameLocks");
this.root.push(new GraphicFrameLockAttributes({ this.root.push(
xmlns: "http://schemas.openxmlformats.org/drawingml/2006/main", new GraphicFrameLockAttributes({
noChangeAspect: 1, xmlns: "http://schemas.openxmlformats.org/drawingml/2006/main",
})); noChangeAspect: 1,
}),
);
} }
} }

View File

@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components";
import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks"; import { GraphicFrameLocks } from "./graphic-frame-locks/graphic-frame-locks";
export class GraphicFrameProperties extends XmlComponent { export class GraphicFrameProperties extends XmlComponent {
constructor() { constructor() {
super("wp:cNvGraphicFramePr"); super("wp:cNvGraphicFramePr");

View File

@ -3,13 +3,14 @@ import { GraphicDataAttributes } from "./graphic-data-attribute";
import { Pic } from "./pic"; import { Pic } from "./pic";
export class GraphicData extends XmlComponent { export class GraphicData extends XmlComponent {
constructor(referenceId: number, x: number, y: number) { constructor(referenceId: number, x: number, y: number) {
super("a:graphicData"); super("a:graphicData");
this.root.push(new GraphicDataAttributes({ this.root.push(
uri: "http://schemas.openxmlformats.org/drawingml/2006/picture", new GraphicDataAttributes({
})); uri: "http://schemas.openxmlformats.org/drawingml/2006/picture",
}),
);
this.root.push(new Pic(referenceId, x, y)); this.root.push(new Pic(referenceId, x, y));
} }

View File

@ -4,7 +4,6 @@ import { SourceRectangle } from "./source-rectangle";
import { Stretch } from "./stretch"; import { Stretch } from "./stretch";
export class BlipFill extends XmlComponent { export class BlipFill extends XmlComponent {
constructor(referenceId: number) { constructor(referenceId: number) {
super("pic:blipFill"); super("pic:blipFill");
this.root.push(new Blip(referenceId)); this.root.push(new Blip(referenceId));

View File

@ -13,12 +13,13 @@ class BlipAttributes extends XmlAttributeComponent<IBlipProperties> {
} }
export class Blip extends XmlComponent { export class Blip extends XmlComponent {
constructor(referenceId: number) { constructor(referenceId: number) {
super("a:blip"); super("a:blip");
this.root.push(new BlipAttributes({ this.root.push(
embed: `rId${referenceId}`, new BlipAttributes({
cstate: "none", embed: `rId${referenceId}`,
})); cstate: "none",
}),
);
} }
} }

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class SourceRectangle extends XmlComponent { export class SourceRectangle extends XmlComponent {
constructor() { constructor() {
super("a:srcRect"); super("a:srcRect");
} }

View File

@ -1,14 +1,12 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
class FillRectangle extends XmlComponent { class FillRectangle extends XmlComponent {
constructor() { constructor() {
super("a:fillRect"); super("a:fillRect");
} }
} }
export class Stretch extends XmlComponent { export class Stretch extends XmlComponent {
constructor() { constructor() {
super("a:stretch"); super("a:stretch");
this.root.push(new FillRectangle()); this.root.push(new FillRectangle());

View File

@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components";
import { PicLocks } from "./pic-locks/pic-locks"; import { PicLocks } from "./pic-locks/pic-locks";
export class ChildNonVisualProperties extends XmlComponent { export class ChildNonVisualProperties extends XmlComponent {
constructor() { constructor() {
super("pic:cNvPicPr"); super("pic:cNvPicPr");

View File

@ -2,12 +2,13 @@ import { XmlComponent } from "file/xml-components";
import { PicLocksAttributes } from "./pic-locks-attributes"; import { PicLocksAttributes } from "./pic-locks-attributes";
export class PicLocks extends XmlComponent { export class PicLocks extends XmlComponent {
constructor() { constructor() {
super("a:picLocks"); super("a:picLocks");
this.root.push(new PicLocksAttributes({ this.root.push(
noChangeAspect: 1, new PicLocksAttributes({
noChangeArrowheads: 1, noChangeAspect: 1,
})); noChangeArrowheads: 1,
}),
);
} }
} }

View File

@ -3,12 +3,10 @@ import { ChildNonVisualProperties } from "./child-non-visual-pic-properties/chil
import { NonVisualProperties } from "./non-visual-properties/non-visual-properties"; import { NonVisualProperties } from "./non-visual-properties/non-visual-properties";
export class NonVisualPicProperties extends XmlComponent { export class NonVisualPicProperties extends XmlComponent {
constructor() { constructor() {
super("pic:nvPicPr"); super("pic:nvPicPr");
this.root.push(new NonVisualProperties()); this.root.push(new NonVisualProperties());
this.root.push(new ChildNonVisualProperties()); this.root.push(new ChildNonVisualProperties());
} }
} }

View File

@ -2,14 +2,15 @@ import { XmlComponent } from "file/xml-components";
import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes"; import { NonVisualPropertiesAttributes } from "./non-visual-properties-attributes";
export class NonVisualProperties extends XmlComponent { export class NonVisualProperties extends XmlComponent {
constructor() { constructor() {
super("pic:cNvPr"); super("pic:cNvPr");
this.root.push(new NonVisualPropertiesAttributes({ this.root.push(
id: 0, new NonVisualPropertiesAttributes({
name: "", id: 0,
descr: "", name: "",
})); descr: "",
}),
);
} }
} }

View File

@ -9,9 +9,11 @@ export class Pic extends XmlComponent {
constructor(referenceId: number, x: number, y: number) { constructor(referenceId: number, x: number, y: number) {
super("pic:pic"); super("pic:pic");
this.root.push(new PicAttributes({ this.root.push(
xmlns: "http://schemas.openxmlformats.org/drawingml/2006/picture", new PicAttributes({
})); xmlns: "http://schemas.openxmlformats.org/drawingml/2006/picture",
}),
);
this.root.push(new NonVisualPicProperties()); this.root.push(new NonVisualPicProperties());
this.root.push(new BlipFill(referenceId)); this.root.push(new BlipFill(referenceId));
this.root.push(new ShapeProperties(x, y)); this.root.push(new ShapeProperties(x, y));

View File

@ -3,13 +3,14 @@ import { XmlComponent } from "file/xml-components";
import { ExtentsAttributes } from "./extents-attributes"; import { ExtentsAttributes } from "./extents-attributes";
export class Extents extends XmlComponent { export class Extents extends XmlComponent {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super("a:ext"); super("a:ext");
this.root.push(new ExtentsAttributes({ this.root.push(
cx: x, new ExtentsAttributes({
cy: y, cx: x,
})); cy: y,
}),
);
} }
} }

View File

@ -4,7 +4,6 @@ import { Extents } from "./extents/extents";
import { Offset } from "./offset/off"; import { Offset } from "./offset/off";
export class Form extends XmlComponent { export class Form extends XmlComponent {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super("a:xfrm"); super("a:xfrm");

View File

@ -3,13 +3,14 @@ import { XmlComponent } from "file/xml-components";
import { OffsetAttributes } from "./off-attributes"; import { OffsetAttributes } from "./off-attributes";
export class Offset extends XmlComponent { export class Offset extends XmlComponent {
constructor() { constructor() {
super("a:off"); super("a:off");
this.root.push(new OffsetAttributes({ this.root.push(
x: 0, new OffsetAttributes({
y: 0, x: 0,
})); y: 0,
}),
);
} }
} }

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class NoFill extends XmlComponent { export class NoFill extends XmlComponent {
constructor() { constructor() {
super("a:noFill"); super("a:noFill");
} }

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class NoFill extends XmlComponent { export class NoFill extends XmlComponent {
constructor() { constructor() {
super("a:noFill"); super("a:noFill");
} }

View File

@ -3,7 +3,6 @@ import { XmlComponent } from "file/xml-components";
import { NoFill } from "./no-fill"; import { NoFill } from "./no-fill";
export class Outline extends XmlComponent { export class Outline extends XmlComponent {
constructor() { constructor() {
super("a:ln"); super("a:ln");

View File

@ -2,7 +2,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class AdjustmentValues extends XmlComponent { export class AdjustmentValues extends XmlComponent {
constructor() { constructor() {
super("a:avLst"); super("a:avLst");
} }

View File

@ -4,13 +4,14 @@ import { AdjustmentValues } from "./adjustment-values/adjustment-values";
import { PresetGeometryAttributes } from "./preset-geometry-attributes"; import { PresetGeometryAttributes } from "./preset-geometry-attributes";
export class PresetGeometry extends XmlComponent { export class PresetGeometry extends XmlComponent {
constructor() { constructor() {
super("a:prstGeom"); super("a:prstGeom");
this.root.push(new PresetGeometryAttributes({ this.root.push(
prst: "rect", new PresetGeometryAttributes({
})); prst: "rect",
}),
);
this.root.push(new AdjustmentValues()); this.root.push(new AdjustmentValues());
} }

View File

@ -7,13 +7,14 @@ import { PresetGeometry } from "./preset-geometry/preset-geometry";
import { ShapePropertiesAttributes } from "./shape-properties-attributes"; import { ShapePropertiesAttributes } from "./shape-properties-attributes";
export class ShapeProperties extends XmlComponent { export class ShapeProperties extends XmlComponent {
constructor(x: number, y: number) { constructor(x: number, y: number) {
super("pic:spPr"); super("pic:spPr");
this.root.push(new ShapePropertiesAttributes({ this.root.push(
bwMode: "auto", new ShapePropertiesAttributes({
})); bwMode: "auto",
}),
);
this.root.push(new Form(x, y)); this.root.push(new Form(x, y));
this.root.push(new PresetGeometry()); this.root.push(new PresetGeometry());

View File

@ -12,12 +12,13 @@ class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> {
} }
export class Graphic extends XmlComponent { export class Graphic extends XmlComponent {
constructor(referenceId: number, x: number, y: number) { constructor(referenceId: number, x: number, y: number) {
super("a:graphic"); super("a:graphic");
this.root.push(new GraphicAttributes({ this.root.push(
a: "http://schemas.openxmlformats.org/drawingml/2006/main", new GraphicAttributes({
})); a: "http://schemas.openxmlformats.org/drawingml/2006/main",
}),
);
this.root.push(new GraphicData(referenceId, x, y)); this.root.push(new GraphicData(referenceId, x, y));
} }
} }

View File

@ -9,16 +9,17 @@ import { GraphicFrameProperties } from "./graphic-frame/graphic-frame-properties
import { InlineAttributes } from "./inline-attributes"; import { InlineAttributes } from "./inline-attributes";
export class Inline extends XmlComponent { export class Inline extends XmlComponent {
constructor(referenceId: number, dimensions: IMediaDataDimensions) { constructor(referenceId: number, dimensions: IMediaDataDimensions) {
super("wp:inline"); super("wp:inline");
this.root.push(new InlineAttributes({ this.root.push(
distT: 0, new InlineAttributes({
distB: 0, distT: 0,
distL: 0, distB: 0,
distR: 0, distL: 0,
})); distR: 0,
}),
);
this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y)); this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y));
this.root.push(new EffectExtent()); this.root.push(new EffectExtent());

View File

@ -9,7 +9,6 @@ import { DefaultStylesFactory } from "./styles/factory";
import { Table } from "./table"; import { Table } from "./table";
export class File { export class File {
private document: Document; private document: Document;
private styles: Styles; private styles: Styles;
private properties: Properties; private properties: Properties;
@ -54,7 +53,11 @@ export class File {
public createImage(image: string): void { public createImage(image: string): void {
const mediaData = this.media.addMedia(image); const mediaData = this.media.addMedia(image);
this.relationships.createRelationship(mediaData.referenceId, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", `media/${mediaData.fileName}`); this.relationships.createRelationship(
mediaData.referenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
`media/${mediaData.fileName}`,
);
this.document.createDrawing(mediaData); this.document.createDrawing(mediaData);
} }

View File

@ -2,7 +2,7 @@ import * as fs from "fs";
import * as sizeOf from "image-size"; import * as sizeOf from "image-size";
import * as path from "path"; import * as path from "path";
import {IMediaData} from "./data"; import { IMediaData } from "./data";
export class Media { export class Media {
private map: Map<string, IMediaData>; private map: Map<string, IMediaData>;

View File

@ -19,10 +19,12 @@ export class AbstractNumbering extends XmlComponent {
constructor(id: number) { constructor(id: number) {
super("w:abstractNum"); super("w:abstractNum");
this.root.push(new AbstractNumberingAttributes({ this.root.push(
abstractNumId: id, new AbstractNumberingAttributes({
restartNumberingAfterBreak: 0, abstractNumId: id,
})); restartNumberingAfterBreak: 0,
}),
);
this.root.push(new MultiLevelType("hybridMultilevel")); this.root.push(new MultiLevelType("hybridMultilevel"));
this.id = id; this.id = id;
} }

View File

@ -17,42 +17,46 @@ class LevelAttributes extends XmlAttributeComponent<ILevelAttributesProperties>
} }
class Start extends XmlComponent { class Start extends XmlComponent {
constructor(value: number) { constructor(value: number) {
super("w:start"); super("w:start");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }
class NumberFormat extends XmlComponent { class NumberFormat extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:numFmt"); super("w:numFmt");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }
class LevelText extends XmlComponent { class LevelText extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:lvlText"); super("w:lvlText");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }
class LevelJc extends XmlComponent { class LevelJc extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:lvlJc"); super("w:lvlJc");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }
@ -62,10 +66,12 @@ export class LevelBase extends XmlComponent {
constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) { constructor(level: number, start?: number, numberFormat?: string, levelText?: string, lvlJc?: string) {
super("w:lvl"); super("w:lvl");
this.root.push(new LevelAttributes({ this.root.push(
ilvl: level, new LevelAttributes({
tentative: 1, ilvl: level,
})); tentative: 1,
}),
);
if (start !== undefined) { if (start !== undefined) {
this.root.push(new Start(start)); this.root.push(new Start(start));

View File

@ -1,11 +1,12 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class MultiLevelType extends XmlComponent { export class MultiLevelType extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:multiLevelType"); super("w:multiLevelType");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }

View File

@ -2,12 +2,13 @@ import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-compon
import { LevelForOverride } from "./level"; import { LevelForOverride } from "./level";
class AbstractNumId extends XmlComponent { class AbstractNumId extends XmlComponent {
constructor(value: number) { constructor(value: number) {
super("w:abstractNumId"); super("w:abstractNumId");
this.root.push(new Attributes({ this.root.push(
val: value, new Attributes({
})); val: value,
}),
);
} }
} }
@ -16,7 +17,7 @@ interface INumAttributesProperties {
} }
class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> { class NumAttributes extends XmlAttributeComponent<INumAttributesProperties> {
protected xmlKeys = {numId: "w:numId"}; protected xmlKeys = { numId: "w:numId" };
} }
export class Num extends XmlComponent { export class Num extends XmlComponent {
@ -24,9 +25,11 @@ export class Num extends XmlComponent {
constructor(numId: number, abstractNumId: number) { constructor(numId: number, abstractNumId: number) {
super("w:num"); super("w:num");
this.root.push(new NumAttributes({ this.root.push(
numId: numId, new NumAttributes({
})); numId: numId,
}),
);
this.root.push(new AbstractNumId(abstractNumId)); this.root.push(new AbstractNumId(abstractNumId));
this.id = numId; this.id = numId;
} }
@ -38,8 +41,8 @@ export class Num extends XmlComponent {
} }
} }
class LevelOverrideAttributes extends XmlAttributeComponent<{ilvl: number}> { class LevelOverrideAttributes extends XmlAttributeComponent<{ ilvl: number }> {
protected xmlKeys = {ilvl: "w:ilvl"}; protected xmlKeys = { ilvl: "w:ilvl" };
} }
export class LevelOverride extends XmlComponent { export class LevelOverride extends XmlComponent {
@ -48,7 +51,7 @@ export class LevelOverride extends XmlComponent {
constructor(levelNum: number, start?: number) { constructor(levelNum: number, start?: number) {
super("w:lvlOverride"); super("w:lvlOverride");
this.root.push(new LevelOverrideAttributes({ilvl: levelNum})); this.root.push(new LevelOverrideAttributes({ ilvl: levelNum }));
if (start !== undefined) { if (start !== undefined) {
this.root.push(new StartOverride(start)); this.root.push(new StartOverride(start));
} }
@ -68,13 +71,13 @@ export class LevelOverride extends XmlComponent {
} }
} }
class StartOverrideAttributes extends XmlAttributeComponent<{val: number}> { class StartOverrideAttributes extends XmlAttributeComponent<{ val: number }> {
protected xmlKeys = {val: "w:val"}; protected xmlKeys = { val: "w:val" };
} }
class StartOverride extends XmlComponent { class StartOverride extends XmlComponent {
constructor(start: number) { constructor(start: number) {
super("w:startOverride"); super("w:startOverride");
this.root.push(new StartOverrideAttributes({val: start})); this.root.push(new StartOverrideAttributes({ val: start }));
} }
} }

View File

@ -6,7 +6,6 @@ import { LevelForOverride } from "./level";
import { Num } from "./num"; import { Num } from "./num";
describe("Numbering", () => { describe("Numbering", () => {
let numbering: Numbering; let numbering: Numbering;
beforeEach(() => { beforeEach(() => {
@ -26,9 +25,7 @@ describe("Numbering", () => {
abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => { abstractNums.filter((el) => el["w:lvl"]).forEach((el, ix) => {
expect(Object.keys(el)).to.have.lengthOf(1); expect(Object.keys(el)).to.have.lengthOf(1);
expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal([ expect(Object.keys(el["w:lvl"]).sort()).to.deep.equal(["_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr"]);
"_attr", "w:start", "w:lvlJc", "w:numFmt", "w:pPr", "w:rPr",
]);
expect(el["w:lvl"]).to.have.deep.members([ expect(el["w:lvl"]).to.have.deep.members([
{ _attr: { "w:ilvl": ix, "w15:tentative": 1 } }, { _attr: { "w:ilvl": ix, "w15:tentative": 1 } },
{ "w:start": [{ _attr: { "w:val": 1 } }] }, { "w:start": [{ _attr: { "w:val": 1 } }] },
@ -63,9 +60,7 @@ describe("Numbering", () => {
const n = numbering.createConcreteNumbering(a2); const n = numbering.createConcreteNumbering(a2);
expect(n).to.be.instanceof(Num); expect(n).to.be.instanceof(Num);
const tree = new Formatter().format(numbering); const tree = new Formatter().format(numbering);
const serializedN = tree["w:numbering"].find((obj) => const serializedN = tree["w:numbering"].find((obj) => obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id);
obj["w:num"] && obj["w:num"][0]._attr["w:numId"] === n.id,
);
expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id); expect(serializedN["w:num"][1]["w:abstractNumId"][0]._attr["w:val"]).to.equal(a2.id);
}); });
@ -110,136 +105,125 @@ describe("AbstractNumbering", () => {
describe("formatting methods: paragraph properties", () => { describe("formatting methods: paragraph properties", () => {
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({ left: 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 } }] }],
}); });
}); });
it("#spacing", () => { it("#spacing", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.") const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").spacing({ before: 50, after: 150 });
.spacing({before: 50, after: 150});
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:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }],
{"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]},
],
}); });
}); });
it("#center", () => { it("#center", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.") const level = abstractNumbering.createLevel(0, "lowerLetter", "%0.").center();
.center();
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:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
{"w:jc": [{_attr: {"w:val": "center"}}]},
],
}); });
}); });
it("#left", () => { it("#left", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.", "left").left();
.left();
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:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
{"w:jc": [{_attr: {"w:val": "left"}}]},
],
}); });
}); });
it("#right", () => { it("#right", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").right();
.right();
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:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
{"w:jc": [{_attr: {"w:val": "right"}}]},
],
}); });
}); });
it("#justified", () => { it("#justified", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").justified();
.justified();
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:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
{"w:jc": [{_attr: {"w:val": "both"}}]},
],
}); });
}); });
it("#thematicBreak", () => { it("#thematicBreak", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").thematicBreak();
.thematicBreak();
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:pPr": [
{"w:pBdr": [{"w:bottom": [{_attr: { {
"w:color": "auto", "w:pBdr": [
"w:space": "1", {
"w:val": "single", "w:bottom": [
"w:sz": "6", {
}}]}]}, _attr: {
"w:color": "auto",
"w:space": "1",
"w:val": "single",
"w:sz": "6",
},
},
],
},
],
},
], ],
}); });
}); });
it("#leftTabStop", () => { it("#leftTabStop", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").leftTabStop(1200);
.leftTabStop(1200);
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:pPr": [
{"w:tabs": [ {
{"w:tab": [{_attr: {"w:val": "left", "w:pos": 1200}}]}, "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }],
]}, },
], ],
}); });
}); });
it("#maxRightTabStop", () => { it("#maxRightTabStop", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").maxRightTabStop();
.maxRightTabStop();
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:pPr": [
{"w:tabs": [ {
{"w:tab": [{_attr: {"w:val": "right", "w:pos": 9026}}]}, "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }],
]}, },
], ],
}); });
}); });
it("#keepLines", () => { it("#keepLines", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepLines();
.keepLines();
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:keepLines": []}], "w:pPr": [{ "w:keepLines": [] }],
}); });
}); });
it("#keepNext", () => { it("#keepNext", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").keepNext();
.keepNext();
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:keepNext": []}], "w:pPr": [{ "w:keepNext": [] }],
}); });
}); });
}); });
@ -247,169 +231,129 @@ describe("AbstractNumbering", () => {
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { it("#size", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").size(24);
.size(24);
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:rPr": [ "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }],
{"w:sz": [{_attr: {"w:val": 24}}]},
],
}); });
}); });
it("#smallCaps", () => { it("#smallCaps", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").smallCaps();
.smallCaps();
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:rPr": [ "w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }],
{"w:smallCaps": [{_attr: {"w:val": true}}]},
],
}); });
}); });
it("#allCaps", () => { it("#allCaps", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").allCaps();
.allCaps();
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:rPr": [ "w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }],
{"w:caps": [{_attr: {"w:val": true}}]},
],
}); });
}); });
it("#strike", () => { it("#strike", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").strike();
.strike();
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:rPr": [ "w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }],
{"w:strike": [{_attr: {"w:val": true}}]},
],
}); });
}); });
it("#doubleStrike", () => { it("#doubleStrike", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").doubleStrike();
.doubleStrike();
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:rPr": [ "w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }],
{"w:dstrike": [{_attr: {"w:val": true}}]},
],
}); });
}); });
it("#subScript", () => { it("#subScript", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").subScript();
.subScript();
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:rPr": [ "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }],
{"w:vertAlign": [{_attr: {"w:val": "subscript"}}]},
],
}); });
}); });
it("#superScript", () => { it("#superScript", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").superScript();
.superScript();
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:rPr": [ "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }],
{"w:vertAlign": [{_attr: {"w:val": "superscript"}}]},
],
}); });
}); });
it("#font", () => { it("#font", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").font("Times");
.font("Times");
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:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}], "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }],
}); });
}); });
it("#bold", () => { it("#bold", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").bold();
.bold();
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:rPr": [ "w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
{"w:b": [{_attr: {"w:val": true}}]},
],
}); });
}); });
it("#italics", () => { it("#italics", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").italics();
.italics();
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:rPr": [ "w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
{"w:i": [{_attr: {"w:val": true}}]},
],
}); });
}); });
describe("#underline", () => { describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => { it("should set underline to 'single' if no arguments are given", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline();
.underline();
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:rPr": [ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }],
{"w:u": [{_attr: {"w:val": "single"}}]},
],
}); });
}); });
it("should set the style if given", () => { it("should set the style if given", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double");
.underline("double");
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:rPr": [ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }],
{"w:u": [{_attr: {"w:val": "double"}}]},
],
}); });
}); });
it("should set the style and color if given", () => { it("should set the style and color if given", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").underline("double", "005599");
.underline("double", "005599");
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:rPr": [ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }],
{"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]},
],
}); });
}); });
}); });
it("#color", () => { it("#color", () => {
const abstractNumbering = new AbstractNumbering(1); const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.") const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").color("123456");
.color("123456");
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:rPr": [ "w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
{"w:color": [{_attr: {"w:val": "123456"}}]},
],
}); });
}); });
}); });
@ -425,23 +369,19 @@ describe("concrete numbering", () => {
numbering = new Numbering(); numbering = new Numbering();
abstractNumbering = numbering.createAbstractNumbering(); abstractNumbering = numbering.createAbstractNumbering();
concreteNumbering = numbering.createConcreteNumbering(abstractNumbering); concreteNumbering = numbering.createConcreteNumbering(abstractNumbering);
}); });
it("sets a new override level for the given level number", () => { it("sets a new override level for the given level number", () => {
concreteNumbering.overrideLevel(3); concreteNumbering.overrideLevel(3);
const tree = new Formatter().format(concreteNumbering); const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({"w:lvlOverride": [{_attr: {"w:ilvl": 3}}]}); expect(tree["w:num"]).to.include({ "w:lvlOverride": [{ _attr: { "w:ilvl": 3 } }] });
}); });
it("sets the startOverride element if start is given", () => { it("sets the startOverride element if start is given", () => {
concreteNumbering.overrideLevel(1, 9); concreteNumbering.overrideLevel(1, 9);
const tree = new Formatter().format(concreteNumbering); const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({ expect(tree["w:num"]).to.include({
"w:lvlOverride": [ "w:lvlOverride": [{ _attr: { "w:ilvl": 1 } }, { "w:startOverride": [{ _attr: { "w:val": 9 } }] }],
{_attr: {"w:ilvl": 1}},
{"w:startOverride": [{_attr: {"w:val": 9}}]},
],
}); });
}); });
@ -451,12 +391,10 @@ describe("concrete numbering", () => {
const tree = new Formatter().format(concreteNumbering); const tree = new Formatter().format(concreteNumbering);
expect(tree["w:num"]).to.include({ expect(tree["w:num"]).to.include({
"w:lvlOverride": [ "w:lvlOverride": [
{_attr: {"w:ilvl": 1}}, { _attr: { "w:ilvl": 1 } },
{"w:lvl": [ {
{_attr: {"w15:tentative": 1, "w:ilvl": 1}}, "w:lvl": [{ _attr: { "w15:tentative": 1, "w:ilvl": 1 } }, { "w:pPr": [] }, { "w:rPr": [] }],
{"w:pPr": []}, },
{"w:rPr": []},
]},
], ],
}); });
}); });

View File

@ -10,63 +10,74 @@ export class Numbering extends XmlComponent {
constructor() { constructor() {
super("w:numbering"); super("w:numbering");
this.root.push(new DocumentAttributes({ this.root.push(
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", new DocumentAttributes({
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
o: "urn:schemas-microsoft-com:office:office", mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", o: "urn:schemas-microsoft-com:office:office",
m: "http://schemas.openxmlformats.org/officeDocument/2006/math", r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
v: "urn:schemas-microsoft-com:vml", m: "http://schemas.openxmlformats.org/officeDocument/2006/math",
wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", v: "urn:schemas-microsoft-com:vml",
wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
w10: "urn:schemas-microsoft-com:office:word", wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", w10: "urn:schemas-microsoft-com:office:word",
w14: "http://schemas.microsoft.com/office/word/2010/wordml", w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
w15: "http://schemas.microsoft.com/office/word/2012/wordml", w14: "http://schemas.microsoft.com/office/word/2010/wordml",
wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", w15: "http://schemas.microsoft.com/office/word/2012/wordml",
wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
wne: "http://schemas.microsoft.com/office/word/2006/wordml", wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", wne: "http://schemas.microsoft.com/office/word/2006/wordml",
Ignorable: "w14 w15 wp14", wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
})); Ignorable: "w14 w15 wp14",
}),
);
this.nextId = 0; this.nextId = 0;
const abstractNumbering = this.createAbstractNumbering(); const abstractNumbering = this.createAbstractNumbering();
abstractNumbering.createLevel(0, "bullet", "•", "left") abstractNumbering
.createLevel(0, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 720, hanging: 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({ left: 1440, hanging: 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({ left: 2160, hanging: 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({ left: 2880, hanging: 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({ left: 3600, hanging: 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({ left: 4320, hanging: 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({ left: 5040, hanging: 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({ left: 5760, hanging: 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({ left: 6480, hanging: 360 })) .addParagraphProperty(new Indent({ left: 6480, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default")); .addRunProperty(new RunFonts("Wingdings", "default"));

View File

@ -3,14 +3,13 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export type AlignmentOptions = "left" | "center" | "right" | "both"; export type AlignmentOptions = "left" | "center" | "right" | "both";
export class AlignmentAttributes extends XmlAttributeComponent<{val: AlignmentOptions}> { export class AlignmentAttributes extends XmlAttributeComponent<{ val: AlignmentOptions }> {
protected xmlKeys = {val: "w:val"}; protected xmlKeys = { val: "w:val" };
} }
export class Alignment extends XmlComponent { export class Alignment extends XmlComponent {
constructor(type: AlignmentOptions) { constructor(type: AlignmentOptions) {
super("w:jc"); super("w:jc");
this.root.push(new AlignmentAttributes({val: type})); this.root.push(new AlignmentAttributes({ val: type }));
} }
} }

View File

@ -2,20 +2,20 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
class Border extends XmlComponent { class Border extends XmlComponent {
constructor() { constructor() {
super("w:bottom"); super("w:bottom");
this.root.push(new Attributes({ this.root.push(
color: "auto", new Attributes({
space: "1", color: "auto",
val: "single", space: "1",
sz: "6", val: "single",
})); sz: "6",
}),
);
} }
} }
export class ThematicBreak extends XmlComponent { export class ThematicBreak extends XmlComponent {
constructor() { constructor() {
super("w:pBdr"); super("w:pBdr");
this.root.push(new Border()); this.root.push(new Border());

View File

@ -20,7 +20,6 @@ class IndentAttributes extends XmlAttributeComponent<IIndentAttributesProperties
} }
export class Indent extends XmlComponent { export class Indent extends XmlComponent {
constructor(attrs: object) { constructor(attrs: object) {
super("w:ind"); super("w:ind");
this.root.push(new IndentAttributes(attrs)); this.root.push(new IndentAttributes(attrs));

View File

@ -3,17 +3,17 @@ import { Attributes, XmlComponent } from "file/xml-components";
import { Run } from "../run"; import { Run } from "../run";
class Break extends XmlComponent { class Break extends XmlComponent {
constructor() { constructor() {
super("w:br"); super("w:br");
this.root.push(new Attributes({ this.root.push(
type: "page", new Attributes({
})); type: "page",
}),
);
} }
} }
export class PageBreak extends Run { export class PageBreak extends Run {
constructor() { constructor() {
super(); super();
this.root.push(new Break()); this.root.push(new Break());

View File

@ -6,18 +6,18 @@ import { Spacing } from "./spacing";
describe("Spacing", () => { describe("Spacing", () => {
describe("#constructor", () => { describe("#constructor", () => {
it("should set the properties given", () => { it("should set the properties given", () => {
const spacing = new Spacing({before: 100, after: 120, line: 150}); const spacing = new Spacing({ before: 100, after: 120, line: 150 });
const tree = new Formatter().format(spacing); const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:spacing": [{_attr: {"w:after": 120, "w:before": 100, "w:line": 150}}], "w:spacing": [{ _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } }],
}); });
}); });
it("should only set the given properties", () => { it("should only set the given properties", () => {
const spacing = new Spacing({before: 100}); const spacing = new Spacing({ before: 100 });
const tree = new Formatter().format(spacing); const tree = new Formatter().format(spacing);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:spacing": [{_attr: {"w:before": 100}}], "w:spacing": [{ _attr: { "w:before": 100 } }],
}); });
}); });
}); });

View File

@ -1,11 +1,12 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class Style extends XmlComponent { export class Style extends XmlComponent {
constructor(type: string) { constructor(type: string) {
super("w:pStyle"); super("w:pStyle");
this.root.push(new Attributes({ this.root.push(
val: type, new Attributes({
})); val: type,
}),
);
} }
} }

View File

@ -2,7 +2,6 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export class TabStop extends XmlComponent { export class TabStop extends XmlComponent {
constructor(tab: Tab) { constructor(tab: Tab) {
super("w:tabs"); super("w:tabs");
this.root.push(tab); this.root.push(tab);
@ -11,18 +10,19 @@ export class TabStop extends XmlComponent {
export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start"; export type TabValue = "left" | "right" | "center" | "bar" | "clear" | "decimal" | "end" | "num" | "start";
export class TabAttributes extends XmlAttributeComponent<{val: TabValue, 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: TabValue, position: string | number) { constructor(value: TabValue, position: string | number) {
super("w:tab"); super("w:tab");
this.root.push(new TabAttributes({ this.root.push(
val: value, new TabAttributes({
pos: position, val: value,
})); pos: position,
}),
);
} }
} }

View File

@ -1,7 +1,6 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export class NumberProperties extends XmlComponent { export class NumberProperties extends XmlComponent {
constructor(numberId: number, indentLevel: number) { constructor(numberId: number, indentLevel: number) {
super("w:numPr"); super("w:numPr");
this.root.push(new IndentLevel(indentLevel)); this.root.push(new IndentLevel(indentLevel));
@ -10,20 +9,23 @@ export class NumberProperties extends XmlComponent {
} }
class IndentLevel extends XmlComponent { class IndentLevel extends XmlComponent {
constructor(level: number) { constructor(level: number) {
super("w:ilvl"); super("w:ilvl");
this.root.push(new Attributes({ this.root.push(
val: level, new Attributes({
})); val: level,
}),
);
} }
} }
class NumberId extends XmlComponent { class NumberId extends XmlComponent {
constructor(id: number) { constructor(id: number) {
super("w:numId"); super("w:numId");
this.root.push(new Attributes({ this.root.push(
val: id, new Attributes({
})); val: id,
}),
);
} }
} }

View File

@ -12,7 +12,6 @@ describe("Paragraph", () => {
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create valid JSON", () => { it("should create valid JSON", () => {
const stringifiedJson = JSON.stringify(paragraph); const stringifiedJson = JSON.stringify(paragraph);
let newJson; let newJson;
@ -37,12 +36,11 @@ describe("Paragraph", () => {
const run = paragraph.createTextRun("this is a test run"); const run = paragraph.createTextRun("this is a test run");
expect(run).to.be.instanceof(file.TextRun); expect(run).to.be.instanceof(file.TextRun);
const tree = new Formatter().format(paragraph)["w:p"]; const tree = new Formatter().format(paragraph)["w:p"];
expect(tree).to.be.an("array").which.includes({ expect(tree)
"w:r": [ .to.be.an("array")
{"w:rPr": []}, .which.includes({
{"w:t": [{_attr: {"xml:space": "preserve"}}, "this is a test run"]}, "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
], });
});
}); });
}); });
@ -53,7 +51,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading1"}}]}], "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading1" } }] }],
}, },
], ],
}); });
@ -67,7 +65,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading2"}}]}], "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading2" } }] }],
}, },
], ],
}); });
@ -81,7 +79,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading3"}}]}], "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading3" } }] }],
}, },
], ],
}); });
@ -95,7 +93,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Title"}}]}], "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Title" } }] }],
}, },
], ],
}); });
@ -109,7 +107,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [{"w:jc": [{_attr: {"w:val": "center"}}]}], "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
}, },
], ],
}); });
@ -121,20 +119,28 @@ describe("Paragraph", () => {
paragraph.thematicBreak(); paragraph.thematicBreak();
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:pBdr": [{ "w:pPr": [
"w:bottom": [{ {
_attr: { "w:pBdr": [
"w:val": "single", {
"w:color": "auto", "w:bottom": [
"w:space": "1", {
"w:sz": "6", _attr: {
}, "w:val": "single",
}], "w:color": "auto",
}], "w:space": "1",
}], "w:sz": "6",
}], },
},
],
},
],
},
],
},
],
}); });
}); });
}); });
@ -144,14 +150,14 @@ describe("Paragraph", () => {
paragraph.pageBreak(); paragraph.pageBreak();
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:br": [{_attr: {"w:type": "page"}}]}, "w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }],
], },
}], ],
}); });
}); });
}); });
@ -160,23 +166,32 @@ describe("Paragraph", () => {
it("should add list paragraph style to JSON", () => { it("should add list paragraph style to JSON", () => {
paragraph.bullet(); paragraph.bullet();
const tree = new Formatter().format(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); expect(tree)
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); .to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}], "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
}); });
}); });
it("it should add numbered properties", () => { it("it should add numbered properties", () => {
paragraph.bullet(); paragraph.bullet();
const tree = new Formatter().format(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); expect(tree)
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2); .to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(2);
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({ expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
"w:numPr": [ "w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 0 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }],
{"w:ilvl": [{_attr: {"w:val": 0}}]},
{"w:numId": [{_attr: {"w:val": 1}}]},
],
}); });
}); });
}); });
@ -190,10 +205,16 @@ describe("Paragraph", () => {
paragraph.setNumbering(letterNumbering, 0); paragraph.setNumbering(letterNumbering, 0);
const tree = new Formatter().format(paragraph); const tree = new Formatter().format(paragraph);
expect(tree).to.have.property("w:p").which.is.an("array").which.has.length.at.least(1); expect(tree)
expect(tree["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1); .to.have.property("w:p")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0])
.to.have.property("w:pPr")
.which.is.an("array")
.which.has.length.at.least(1);
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({ expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}], "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
}); });
}); });
@ -209,11 +230,11 @@ describe("Paragraph", () => {
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [
{"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}]}, { "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }] },
{ {
"w:numPr": [ "w:numPr": [
{"w:ilvl": [{_attr: {"w:val": 0}}]}, { "w:ilvl": [{ _attr: { "w:val": 0 } }] },
{"w:numId": [{_attr: {"w:val": letterNumbering.id}}]}, { "w:numId": [{ _attr: { "w:val": letterNumbering.id } }] },
], ],
}, },
], ],
@ -230,9 +251,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "myFancyStyle" } }] }],
{"w:pStyle": [{_attr: {"w:val": "myFancyStyle"}}]},
],
}, },
], ],
}); });
@ -246,9 +265,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:p": [ "w:p": [
{ {
"w:pPr": [ "w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
{"w:ind": [{_attr: {"w:left": 720}}]},
],
}, },
], ],
}); });
@ -257,14 +274,12 @@ describe("Paragraph", () => {
describe("#spacing", () => { describe("#spacing", () => {
it("should set the paragraph spacing to the given values", () => { it("should set the paragraph spacing to the given values", () => {
paragraph.spacing({before: 90, line: 50}); paragraph.spacing({ before: 90, line: 50 });
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:spacing": [{ _attr: { "w:before": 90, "w:line": 50 } }] }],
{"w:spacing": [{_attr: {"w:before": 90, "w:line": 50}}]},
],
}, },
], ],
}); });
@ -276,7 +291,7 @@ describe("Paragraph", () => {
paragraph.keepLines(); paragraph.keepLines();
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:pPr": [{"w:keepLines": []}]}], "w:p": [{ "w:pPr": [{ "w:keepLines": [] }] }],
}); });
}); });
}); });
@ -286,7 +301,7 @@ describe("Paragraph", () => {
paragraph.keepNext(); paragraph.keepNext();
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:pPr": [{"w:keepNext": []}]}], "w:p": [{ "w:pPr": [{ "w:keepNext": [] }] }],
}); });
}); });
}); });

View File

@ -2,7 +2,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class ParagraphProperties extends XmlComponent { export class ParagraphProperties extends XmlComponent {
constructor() { constructor() {
super("w:pPr"); super("w:pPr");
} }

View File

@ -2,7 +2,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class Break extends XmlComponent { export class Break extends XmlComponent {
constructor() { constructor() {
super("w:br"); super("w:br");
} }

View File

@ -1,14 +1,12 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class SmallCaps extends XmlComponent { export class SmallCaps extends XmlComponent {
constructor() { constructor() {
super("w:smallCaps"); super("w:smallCaps");
} }
} }
export class Caps extends XmlComponent { export class Caps extends XmlComponent {
constructor() { constructor() {
super("w:caps"); super("w:caps");
} }

View File

@ -4,111 +4,122 @@ export { SubScript, SuperScript } from "./script";
export { RunFonts } from "./run-fonts"; export { RunFonts } from "./run-fonts";
export class Bold extends XmlComponent { export class Bold extends XmlComponent {
constructor() { constructor() {
super("w:b"); super("w:b");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Italics extends XmlComponent { export class Italics extends XmlComponent {
constructor() { constructor() {
super("w:i"); super("w:i");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Caps extends XmlComponent { export class Caps extends XmlComponent {
constructor() { constructor() {
super("w:caps"); super("w:caps");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Color extends XmlComponent { export class Color extends XmlComponent {
constructor(color: string) { constructor(color: string) {
super("w:color"); super("w:color");
this.root.push(new Attributes({ this.root.push(
val: color, new Attributes({
})); val: color,
}),
);
} }
} }
export class DoubleStrike extends XmlComponent { export class DoubleStrike extends XmlComponent {
constructor() { constructor() {
super("w:dstrike"); super("w:dstrike");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Emboss extends XmlComponent { export class Emboss extends XmlComponent {
constructor() { constructor() {
super("w:emboss"); super("w:emboss");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Imprint extends XmlComponent { export class Imprint extends XmlComponent {
constructor() { constructor() {
super("w:imprint"); super("w:imprint");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Shadow extends XmlComponent { export class Shadow extends XmlComponent {
constructor() { constructor() {
super("w:shadow"); super("w:shadow");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class SmallCaps extends XmlComponent { export class SmallCaps extends XmlComponent {
constructor() { constructor() {
super("w:smallCaps"); super("w:smallCaps");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Strike extends XmlComponent { export class Strike extends XmlComponent {
constructor() { constructor() {
super("w:strike"); super("w:strike");
this.root.push(new Attributes({ this.root.push(
val: true, new Attributes({
})); val: true,
}),
);
} }
} }
export class Size extends XmlComponent { export class Size extends XmlComponent {
constructor(size: number) { constructor(size: number) {
super("w:sz"); super("w:sz");
this.root.push(new Attributes({ this.root.push(
val: size, new Attributes({
})); val: size,
}),
);
} }
} }

View File

@ -3,7 +3,6 @@ import { IMediaData } from "../../media/data";
import { Run } from "../run"; import { Run } from "../run";
export class PictureRun extends Run { export class PictureRun extends Run {
constructor(imageData: IMediaData) { constructor(imageData: IMediaData) {
super(); super();

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class RunProperties extends XmlComponent { export class RunProperties extends XmlComponent {
constructor() { constructor() {
super("w:rPr"); super("w:rPr");
} }

View File

@ -8,16 +8,15 @@ describe("Text", () => {
it("creates an empty text run if no text is given", () => { it("creates an empty text run if no text is given", () => {
const t = new Text(""); const t = new Text("");
const f = new Formatter().format(t); const f = new Formatter().format(t);
expect(f).to.deep.equal({"w:t": [{_attr: {"xml:space": "preserve"}}]}); expect(f).to.deep.equal({ "w:t": [{ _attr: { "xml:space": "preserve" } }] });
}); });
it("adds the passed in text to the component", () => { it("adds the passed in text to the component", () => {
const t = new Text(" this is\n text"); const t = new Text(" this is\n text");
const f = new Formatter().format(t); const f = new Formatter().format(t);
expect(f).to.deep.equal({"w:t": [ expect(f).to.deep.equal({
{_attr: {"xml:space": "preserve"}}, "w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
" this is\n text", });
]});
}); });
}); });
}); });

View File

@ -1,13 +1,13 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class TextAttributes extends XmlAttributeComponent<{space: "default" | "preserve"}> { class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
protected xmlKeys = {space: "xml:space"}; protected xmlKeys = { space: "xml:space" };
} }
export class Text extends XmlComponent { export class Text extends XmlComponent {
constructor(text: string) { constructor(text: string) {
super("w:t"); super("w:t");
this.root.push(new TextAttributes({space: "preserve"})); this.root.push(new TextAttributes({ space: "preserve" }));
if (text) { if (text) {
this.root.push(text); this.root.push(text);
} }

View File

@ -4,19 +4,18 @@ import { Formatter } from "../../../export/formatter";
import { RunFonts } from "./run-fonts"; import { RunFonts } from "./run-fonts";
describe("RunFonts", () => { describe("RunFonts", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => { it("uses the font name for both ascii and hAnsi", () => {
const tree = new Formatter().format(new RunFonts("Times")); const tree = new Formatter().format(new RunFonts("Times"));
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}], "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }],
}); });
}); });
it("uses hint if given", () => { it("uses hint if given", () => {
const tree = new Formatter().format(new RunFonts("Times", "default")); const tree = new Formatter().format(new RunFonts("Times", "default"));
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}], "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default" } }],
}); });
}); });
}); });

View File

@ -15,13 +15,14 @@ class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperti
} }
export class RunFonts extends XmlComponent { export class RunFonts extends XmlComponent {
constructor(ascii: string, hint?: string) { constructor(ascii: string, hint?: string) {
super("w:rFonts"); super("w:rFonts");
this.root.push(new RunFontAttributes({ this.root.push(
ascii: ascii, new RunFontAttributes({
hAnsi: ascii, ascii: ascii,
hint: hint, hAnsi: ascii,
})); hint: hint,
}),
);
} }
} }

View File

@ -38,9 +38,7 @@ describe("Run", () => {
run.underline(); run.underline();
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }] }],
{"w:rPr": [{"w:u": [{_attr: {"w:val": "single"}}]}]},
],
}); });
}); });
@ -48,9 +46,7 @@ describe("Run", () => {
run.underline("double", "990011"); run.underline("double", "990011");
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "990011" } }] }] }],
{"w:rPr": [{"w:u": [{_attr: {"w:val": "double", "w:color": "990011"}}]}]},
],
}); });
}); });
}); });
@ -112,9 +108,7 @@ describe("Run", () => {
run.font("Times"); run.font("Times");
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] }],
{"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]},
],
}); });
}); });
}); });
@ -124,9 +118,7 @@ describe("Run", () => {
run.color("001122"); run.color("001122");
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:color": [{ _attr: { "w:val": "001122" } }] }] }],
{"w:rPr": [{"w:color": [{_attr: {"w:val": "001122"}}]}]},
],
}); });
}); });
}); });
@ -136,9 +128,7 @@ describe("Run", () => {
run.size(24); run.size(24);
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }] }],
{"w:rPr": [{"w:sz": [{_attr: {"w:val": 24}}]}]},
],
}); });
}); });
}); });
@ -148,9 +138,7 @@ describe("Run", () => {
run.style("myRunStyle"); run.style("myRunStyle");
const tree = new Formatter().format(run); const tree = new Formatter().format(run);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:r": [ "w:r": [{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "myRunStyle" } }] }] }],
{"w:rPr": [{"w:rStyle": [{_attr: {"w:val": "myRunStyle"}}]}]},
],
}); });
}); });
}); });

View File

@ -1,24 +1,23 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export abstract class VerticalAlign extends XmlComponent { export abstract class VerticalAlign extends XmlComponent {
constructor(type: string) { constructor(type: string) {
super("w:vertAlign"); super("w:vertAlign");
this.root.push(new Attributes({ this.root.push(
val: type, new Attributes({
})); val: type,
}),
);
} }
} }
export class SuperScript extends VerticalAlign { export class SuperScript extends VerticalAlign {
constructor() { constructor() {
super("superscript"); super("superscript");
} }
} }
export class SubScript extends VerticalAlign { export class SubScript extends VerticalAlign {
constructor() { constructor() {
super("subscript"); super("subscript");
} }

View File

@ -1,13 +1,12 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
class StyleAttributes extends XmlAttributeComponent<{val: string}> { class StyleAttributes extends XmlAttributeComponent<{ val: string }> {
protected xmlKeys = {val: "w:val"}; protected xmlKeys = { val: "w:val" };
} }
export class Style extends XmlComponent { export class Style extends XmlComponent {
constructor(styleId: string) { constructor(styleId: string) {
super("w:rStyle"); super("w:rStyle");
this.root.push(new StyleAttributes({val: styleId})); this.root.push(new StyleAttributes({ val: styleId }));
} }
} }

View File

@ -1,7 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
export class Tab extends XmlComponent { export class Tab extends XmlComponent {
constructor() { constructor() {
super("w:tab"); super("w:tab");
} }

View File

@ -7,14 +7,12 @@ describe("TextRun", () => {
let run: TextRun; let run: TextRun;
describe("#constructor()", () => { describe("#constructor()", () => {
it("should add text into run", () => { it("should add text into run", () => {
run = new TextRun("test"); run = new TextRun("test");
const f = new Formatter().format(run); const f = new Formatter().format(run);
expect(f).to.deep.equal({"w:r": [ expect(f).to.deep.equal({
{"w:rPr": []}, "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }],
{"w:t": [{_attr: {"xml:space": "preserve"}}, "test"]}, });
]});
}); });
}); });
}); });

View File

@ -2,7 +2,6 @@ import { Run } from "../run";
import { Text } from "./run-components/text"; import { Text } from "./run-components/text";
export class TextRun extends Run { export class TextRun extends Run {
constructor(text: string) { constructor(text: string) {
super(); super();
this.root.push(new Text(text)); this.root.push(new Text(text));

View File

@ -5,9 +5,7 @@ import { Utility } from "../../../tests/utility";
import * as u from "./underline"; import * as u from "./underline";
describe("Underline", () => { describe("Underline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create a new Underline object with u:u as the rootKey", () => { it("should create a new Underline object with u:u as the rootKey", () => {
const underline = new u.Underline(); const underline = new u.Underline();
const newJson = Utility.jsonify(underline); const newJson = Utility.jsonify(underline);
@ -18,7 +16,7 @@ describe("Underline", () => {
const underline = new u.Underline(); const underline = new u.Underline();
const tree = new Formatter().format(underline); const tree = new Formatter().format(underline);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:u": [{_attr: {"w:val": "single"}}], "w:u": [{ _attr: { "w:val": "single" } }],
}); });
}); });
@ -26,14 +24,13 @@ describe("Underline", () => {
const underline = new u.Underline("double", "FF00CC"); const underline = new u.Underline("double", "FF00CC");
const tree = new Formatter().format(underline); const tree = new Formatter().format(underline);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:u": [{_attr: {"w:val": "double", "w:color": "FF00CC"}}], "w:u": [{ _attr: { "w:val": "double", "w:color": "FF00CC" } }],
}); });
}); });
}); });
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should have u:u as the rootKey", () => { it("should have u:u as the rootKey", () => {
const underline = new u.DashDotDotHeavyUnderline(); const underline = new u.DashDotDotHeavyUnderline();
@ -50,7 +47,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashDotHeavyUnderline(); const underline = new u.DashDotHeavyUnderline();
@ -61,7 +57,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashLongHeavyUnderline(); const underline = new u.DashLongHeavyUnderline();
@ -72,7 +67,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashLongUnderline(); const underline = new u.DashLongUnderline();
@ -83,7 +77,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DashUnderline(); const underline = new u.DashUnderline();
@ -94,7 +87,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DotDashUnderline(); const underline = new u.DotDashUnderline();
@ -105,7 +97,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DotDotDashUnderline(); const underline = new u.DotDotDashUnderline();
@ -116,7 +107,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DottedHeavyUnderline(); const underline = new u.DottedHeavyUnderline();
@ -127,7 +117,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DottedUnderline(); const underline = new u.DottedUnderline();
@ -138,7 +127,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.DoubleUnderline(); const underline = new u.DoubleUnderline();
@ -149,7 +137,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.SingleUnderline(); const underline = new u.SingleUnderline();
@ -160,7 +147,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.ThickUnderline(); const underline = new u.ThickUnderline();
@ -171,7 +157,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WaveUnderline(); const underline = new u.WaveUnderline();
@ -182,7 +167,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WavyDoubleUnderline(); const underline = new u.WavyDoubleUnderline();
@ -193,7 +177,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WavyHeavyUnderline(); const underline = new u.WavyHeavyUnderline();
@ -204,7 +187,6 @@ describe("DashDotDotHeavyUnderline", () => {
}); });
describe("DashDotDotHeavyUnderline", () => { describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should put value in attribute", () => { it("should put value in attribute", () => {
const underline = new u.WordsUnderline(); const underline = new u.WordsUnderline();

View File

@ -1,130 +1,114 @@
import { Attributes, XmlComponent } from "file/xml-components"; import { Attributes, XmlComponent } from "file/xml-components";
export abstract class BaseUnderline extends XmlComponent { export abstract class BaseUnderline extends XmlComponent {
constructor(underlineType: string, color?: string) { constructor(underlineType: string, color?: string) {
super("w:u"); super("w:u");
this.root.push(new Attributes({ this.root.push(
val: underlineType, new Attributes({
color: color, val: underlineType,
})); color: color,
}),
);
} }
} }
export class Underline extends BaseUnderline { export class Underline extends BaseUnderline {
constructor(underlineType: string = "single", color?: string) { constructor(underlineType: string = "single", color?: string) {
super(underlineType, color); super(underlineType, color);
} }
} }
export class DashUnderline extends BaseUnderline { export class DashUnderline extends BaseUnderline {
constructor() { constructor() {
super("dash"); super("dash");
} }
} }
export class DashDotDotHeavyUnderline extends BaseUnderline { export class DashDotDotHeavyUnderline extends BaseUnderline {
constructor() { constructor() {
super("dashDotDotHeavy"); super("dashDotDotHeavy");
} }
} }
export class DashDotHeavyUnderline extends BaseUnderline { export class DashDotHeavyUnderline extends BaseUnderline {
constructor() { constructor() {
super("dashDotHeavy"); super("dashDotHeavy");
} }
} }
export class DashLongUnderline extends BaseUnderline { export class DashLongUnderline extends BaseUnderline {
constructor() { constructor() {
super("dashLong"); super("dashLong");
} }
} }
export class DashLongHeavyUnderline extends BaseUnderline { export class DashLongHeavyUnderline extends BaseUnderline {
constructor() { constructor() {
super("dashLongHeavy"); super("dashLongHeavy");
} }
} }
export class DotDashUnderline extends BaseUnderline { export class DotDashUnderline extends BaseUnderline {
constructor() { constructor() {
super("dotDash"); super("dotDash");
} }
} }
export class DotDotDashUnderline extends BaseUnderline { export class DotDotDashUnderline extends BaseUnderline {
constructor() { constructor() {
super("dotDotDash"); super("dotDotDash");
} }
} }
export class DottedUnderline extends BaseUnderline { export class DottedUnderline extends BaseUnderline {
constructor() { constructor() {
super("dotted"); super("dotted");
} }
} }
export class DottedHeavyUnderline extends BaseUnderline { export class DottedHeavyUnderline extends BaseUnderline {
constructor() { constructor() {
super("dottedHeavy"); super("dottedHeavy");
} }
} }
export class DoubleUnderline extends BaseUnderline { export class DoubleUnderline extends BaseUnderline {
constructor() { constructor() {
super("double"); super("double");
} }
} }
export class SingleUnderline extends BaseUnderline { export class SingleUnderline extends BaseUnderline {
constructor() { constructor() {
super("single"); super("single");
} }
} }
export class ThickUnderline extends BaseUnderline { export class ThickUnderline extends BaseUnderline {
constructor() { constructor() {
super("thick"); super("thick");
} }
} }
export class WaveUnderline extends BaseUnderline { export class WaveUnderline extends BaseUnderline {
constructor() { constructor() {
super("wave"); super("wave");
} }
} }
export class WavyDoubleUnderline extends BaseUnderline { export class WavyDoubleUnderline extends BaseUnderline {
constructor() { constructor() {
super("wavyDouble"); super("wavyDouble");
} }
} }
export class WavyHeavyUnderline extends BaseUnderline { export class WavyHeavyUnderline extends BaseUnderline {
constructor() { constructor() {
super("wavyHeavy"); super("wavyHeavy");
} }
} }
export class WordsUnderline extends BaseUnderline { export class WordsUnderline extends BaseUnderline {
constructor() { constructor() {
super("words"); super("words");
} }

View File

@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components";
import { DocumentAttributes } from "../document/document-attributes"; import { DocumentAttributes } from "../document/document-attributes";
export class Title extends XmlComponent { export class Title extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("dc:title"); super("dc:title");
this.root.push(value); this.root.push(value);
@ -10,7 +9,6 @@ export class Title extends XmlComponent {
} }
export class Subject extends XmlComponent { export class Subject extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("dc:subject"); super("dc:subject");
this.root.push(value); this.root.push(value);
@ -18,7 +16,6 @@ export class Subject extends XmlComponent {
} }
export class Creator extends XmlComponent { export class Creator extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("dc:creator"); super("dc:creator");
this.root.push(value); this.root.push(value);
@ -26,7 +23,6 @@ export class Creator extends XmlComponent {
} }
export class Keywords extends XmlComponent { export class Keywords extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("cp:keywords"); super("cp:keywords");
this.root.push(value); this.root.push(value);
@ -34,7 +30,6 @@ export class Keywords extends XmlComponent {
} }
export class Description extends XmlComponent { export class Description extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("dc:description"); super("dc:description");
this.root.push(value); this.root.push(value);
@ -42,7 +37,6 @@ export class Description extends XmlComponent {
} }
export class LastModifiedBy extends XmlComponent { export class LastModifiedBy extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("cp:lastModifiedBy"); super("cp:lastModifiedBy");
this.root.push(value); this.root.push(value);
@ -50,7 +44,6 @@ export class LastModifiedBy extends XmlComponent {
} }
export class Revision extends XmlComponent { export class Revision extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("cp:revision"); super("cp:revision");
this.root.push(value); this.root.push(value);
@ -72,23 +65,25 @@ export abstract class DateComponent extends XmlComponent {
} }
export class Created extends DateComponent { export class Created extends DateComponent {
constructor() { constructor() {
super("dcterms:created"); super("dcterms:created");
this.root.push(new DocumentAttributes({ this.root.push(
type: "dcterms:W3CDTF", new DocumentAttributes({
})); type: "dcterms:W3CDTF",
}),
);
this.root.push(this.getCurrentDate()); this.root.push(this.getCurrentDate());
} }
} }
export class Modified extends DateComponent { export class Modified extends DateComponent {
constructor() { constructor() {
super("dcterms:modified"); super("dcterms:modified");
this.root.push(new DocumentAttributes({ this.root.push(
type: "dcterms:W3CDTF", new DocumentAttributes({
})); type: "dcterms:W3CDTF",
}),
);
this.root.push(this.getCurrentDate()); this.root.push(this.getCurrentDate());
} }
} }

View File

@ -4,7 +4,6 @@ import { Formatter } from "../../export/formatter";
import { Properties } from "./properties"; import { Properties } from "./properties";
describe("Properties", () => { describe("Properties", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("sets the appropriate attributes on the top-level", () => { it("sets the appropriate attributes on the top-level", () => {
const properties = new Properties({}); const properties = new Properties({});
@ -23,14 +22,12 @@ describe("Properties", () => {
}); });
it("should create properties with a title", () => { it("should create properties with a title", () => {
const properties = new Properties({title: "test document"}); const properties = new Properties({ title: "test document" });
const tree = new Formatter().format(properties); const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]); expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array); expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
expect(Object.keys(tree["cp:coreProperties"][0])).to.deep.equal(["_attr"]); expect(Object.keys(tree["cp:coreProperties"][0])).to.deep.equal(["_attr"]);
expect(tree["cp:coreProperties"][1]).to.deep.equal( expect(tree["cp:coreProperties"][1]).to.deep.equal({ "dc:title": ["test document"] });
{"dc:title": ["test document"]},
);
}); });
it("should create properties with all the attributes given", () => { it("should create properties with all the attributes given", () => {
@ -60,14 +57,14 @@ describe("Properties", () => {
"dcterms:created", "dcterms:created",
"dcterms:modified", "dcterms:modified",
]); ]);
expect(tree["cp:coreProperties"].slice(1, -2).sort((a, b) => key(a) < key(b) ? -1 : 1)).to.deep.equal([ expect(tree["cp:coreProperties"].slice(1, -2).sort((a, b) => (key(a) < key(b) ? -1 : 1))).to.deep.equal([
{"cp:keywords": ["test docx"]}, { "cp:keywords": ["test docx"] },
{"cp:lastModifiedBy": ["the author"]}, { "cp:lastModifiedBy": ["the author"] },
{"cp:revision": ["123"]}, { "cp:revision": ["123"] },
{"dc:creator": ["me"]}, { "dc:creator": ["me"] },
{"dc:description": ["testing document"]}, { "dc:description": ["testing document"] },
{"dc:subject": ["test subject"]}, { "dc:subject": ["test subject"] },
{"dc:title": ["test document"]}, { "dc:title": ["test document"] },
]); ]);
}); });
}); });

View File

@ -13,16 +13,17 @@ export interface IPropertiesOptions {
} }
export class Properties extends XmlComponent { export class Properties extends XmlComponent {
constructor(options: IPropertiesOptions) { constructor(options: IPropertiesOptions) {
super("cp:coreProperties"); super("cp:coreProperties");
this.root.push(new DocumentAttributes({ this.root.push(
cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", new DocumentAttributes({
dc: "http://purl.org/dc/elements/1.1/", cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
dcterms: "http://purl.org/dc/terms/", dc: "http://purl.org/dc/elements/1.1/",
dcmitype: "http://purl.org/dc/dcmitype/", dcterms: "http://purl.org/dc/terms/",
xsi: "http://www.w3.org/2001/XMLSchema-instance", dcmitype: "http://purl.org/dc/dcmitype/",
})); xsi: "http://www.w3.org/2001/XMLSchema-instance",
}),
);
if (options.title) { if (options.title) {
this.root.push(new Title(options.title)); this.root.push(new Title(options.title));
} }

View File

@ -14,10 +14,12 @@ export class Relationship extends XmlComponent {
constructor(id: string, type: RelationshipType, target: string) { constructor(id: string, type: RelationshipType, target: string) {
super("Relationship"); super("Relationship");
this.root.push(new RelationshipAttributes({ this.root.push(
id, new RelationshipAttributes({
type, id,
target, type,
})); target,
}),
);
} }
} }

View File

@ -3,12 +3,13 @@ import { RelationshipsAttributes } from "./attributes";
import { Relationship, RelationshipType } from "./relationship/relationship"; import { Relationship, RelationshipType } from "./relationship/relationship";
export class Relationships extends XmlComponent { export class Relationships extends XmlComponent {
constructor() { constructor() {
super("Relationships"); super("Relationships");
this.root.push(new RelationshipsAttributes({ this.root.push(
xmlns: "http://schemas.openxmlformats.org/package/2006/relationships", new RelationshipsAttributes({
})); xmlns: "http://schemas.openxmlformats.org/package/2006/relationships",
}),
);
this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml"); this.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml"); this.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");

View File

@ -3,7 +3,6 @@ import { ParagraphPropertiesDefaults } from "./paragraph-properties";
import { RunPropertiesDefaults } from "./run-properties"; import { RunPropertiesDefaults } from "./run-properties";
export class DocumentDefaults extends XmlComponent { export class DocumentDefaults extends XmlComponent {
private runPropertiesDefaults: RunPropertiesDefaults; private runPropertiesDefaults: RunPropertiesDefaults;
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults; private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;

View File

@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components";
import { ParagraphProperties } from "../../paragraph/properties"; import { ParagraphProperties } from "../../paragraph/properties";
export class ParagraphPropertiesDefaults extends XmlComponent { export class ParagraphPropertiesDefaults extends XmlComponent {
constructor() { constructor() {
super("w:pPrDefault"); super("w:pPrDefault");
this.root.push(new ParagraphProperties()); this.root.push(new ParagraphProperties());

View File

@ -3,12 +3,17 @@ import { Color, Italics, Size } from "../paragraph/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,
ListParagraph, TitleStyle, Heading2Style,
Heading3Style,
Heading4Style,
Heading5Style,
Heading6Style,
ListParagraph,
TitleStyle,
} from "./style"; } from "./style";
export class DefaultStylesFactory { export class DefaultStylesFactory {
public newInstance(): Styles { public newInstance(): Styles {
const styles = new Styles(); const styles = new Styles();
styles.createDocumentDefaults(); styles.createDocumentDefaults();

View File

@ -4,18 +4,18 @@ import { DocumentDefaults } from "./defaults";
import { ParagraphStyle } from "./style"; import { ParagraphStyle } from "./style";
export class Styles extends XmlComponent { export class Styles extends XmlComponent {
constructor() { constructor() {
super("w:styles"); super("w:styles");
this.root.push(new DocumentAttributes({ this.root.push(
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", new DocumentAttributes({
r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
w14: "http://schemas.microsoft.com/office/word/2010/wordml", w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
w15: "http://schemas.microsoft.com/office/word/2012/wordml", w14: "http://schemas.microsoft.com/office/word/2010/wordml",
Ignorable: "w14 w15", w15: "http://schemas.microsoft.com/office/word/2012/wordml",
})); Ignorable: "w14 w15",
}),
);
} }
public push(style: XmlComponent): Styles { public push(style: XmlComponent): Styles {

View File

@ -19,7 +19,6 @@ export class LatentStyleExceptionAttributes extends XmlAttributeComponent<ILaten
} }
export class LatentStyleException extends XmlComponent { export class LatentStyleException extends XmlComponent {
constructor(attributes: ILatentStyleExceptionAttributesProperties) { constructor(attributes: ILatentStyleExceptionAttributesProperties) {
super("w:lsdException"); super("w:lsdException");
this.root.push(new LatentStyleExceptionAttributes(attributes)); this.root.push(new LatentStyleExceptionAttributes(attributes));

View File

@ -2,7 +2,6 @@ import { XmlComponent } from "file/xml-components";
import { LatentStyleException } from "./exceptions"; import { LatentStyleException } from "./exceptions";
export class LatentStyles extends XmlComponent { export class LatentStyles extends XmlComponent {
constructor() { constructor() {
super("w:latentStyles"); super("w:latentStyles");
} }

View File

@ -1,149 +1,211 @@
/* tslint:disable */ /* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) { function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
'use strict'; "use strict";
return [{ return [
_attr: { {
'w:name': name, _attr: {
'w:uiPriority': uiPriority, "w:name": name,
'w:qFormat': qFormat, "w:uiPriority": uiPriority,
'w:semiHidden': semiHidden, "w:qFormat": qFormat,
'w:unhideWhenUsed': unhideWhenUsed "w:semiHidden": semiHidden,
} "w:unhideWhenUsed": unhideWhenUsed,
}]; },
},
];
} }
export function DefaultStyle() { export function DefaultStyle() {
var style = { var style = {
'w:styles': [{ "w:styles": [
_attr: { {
'xmlns:mc': 'http://schemas.openxmlformats.org/markup-compatibility/2006',
'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
'xmlns:w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
'xmlns:w14': 'http://schemas.microsoft.com/office/word/2010/wordml',
'xmlns:w15': 'http://schemas.microsoft.com/office/word/2012/wordml',
'mc:Ignorable': 'w14 w15'
}
}, {
'w:docDefaults': [{
'w:rPrDefault': [{
'w:rPr': [{
'w:rFonts': [{
_attr: {
'w:asciiTheme': "minorHAnsi",
'w:eastAsiaTheme': "minorHAnsi",
'w:hAnsiTheme': "minorHAnsi",
'w:cstheme': "minorBidi"
}
}]
}, {
'w:sz': [{
_attr: {
'w:val': "22"
}
}]
}, {
'w:szCs': [{
_attr: {
'w:val': "22"
}
}]
}, {
'w:lang': [{
_attr: {
'w:val': "en-GB",
'w:eastAsia': "en-US",
'w:bidi': "ar-SA"
}
}]
}]
}]
}, {
'w:pPrDefault': [{
'w:pPr': [{
'w:spacing': [{
_attr: {
'w:after': "160",
'w:line': "259",
'w:lineRule': "auto"
}
}]
}]
}]
}]
}, {
'w:latentStyles': [{
_attr: { _attr: {
'w:defLockedState': "0", "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
'w:defUIPriority': "99", "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
'w:defSemiHidden': "0", "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
'w:defUnhideWhenUsed': "0", "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
'w:defQFormat': "0", "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
'w:count': "371" "mc:Ignorable": "w14 w15",
} },
}, { },
'w:lsdException': createLsdException('Normal', 0, 1) {
}, { "w:docDefaults": [
'w:lsdException': createLsdException("heading 1", 9, 1, 1, 1) {
}, { "w:rPrDefault": [
'w:lsdException': createLsdException("heading 2", 9, 1, 1, 1) {
}, { "w:rPr": [
'w:lsdException': createLsdException("heading 3", 9, 1, 1, 1) {
}, { "w:rFonts": [
'w:lsdException': createLsdException("heading 4", 9, 1, 1, 1) {
}, { _attr: {
'w:lsdException': createLsdException("heading 5", 9, 1, 1, 1) "w:asciiTheme": "minorHAnsi",
}, { "w:eastAsiaTheme": "minorHAnsi",
'w:lsdException': createLsdException("heading 6", 9, 1, 1, 1) "w:hAnsiTheme": "minorHAnsi",
}, { "w:cstheme": "minorBidi",
'w:lsdException': createLsdException("heading 7", 9, 1, 1, 1) },
}, { },
'w:lsdException': createLsdException("heading 8", 9, 1, 1, 1) ],
}, { },
'w:lsdException': createLsdException("heading 9", 9, 1, 1, 1) {
}, { "w:sz": [
'w:lsdException': createLsdException("index 1", undefined, undefined, 1, 1) {
}, { _attr: {
'w:lsdException': createLsdException("index 2", undefined, undefined, 1, 1) "w:val": "22",
}, { },
'w:lsdException': createLsdException("index 3", undefined, undefined, 1, 1) },
}, { ],
'w:lsdException': createLsdException("index 4", undefined, undefined, 1, 1) },
}, { {
'w:lsdException': createLsdException("index 5", undefined, undefined, 1, 1) "w:szCs": [
}, { {
'w:lsdException': createLsdException("index 6", undefined, undefined, 1, 1) _attr: {
}, { "w:val": "22",
'w:lsdException': createLsdException("index 7", undefined, undefined, 1, 1) },
}, { },
'w:lsdException': createLsdException("index 8", undefined, undefined, 1, 1) ],
}, { },
'w:lsdException': createLsdException("index 9", undefined, undefined, 1, 1) {
}, { "w:lang": [
'w:lsdException': createLsdException("toc 1", 39, undefined, 1, 1) {
}, { _attr: {
'w:lsdException': createLsdException("toc 2", 39, undefined, 1, 1) "w:val": "en-GB",
}, { "w:eastAsia": "en-US",
'w:lsdException': createLsdException("toc 3", 39, undefined, 1, 1) "w:bidi": "ar-SA",
}, { },
'w:lsdException': createLsdException("toc 4", 39, undefined, 1, 1) },
}, { ],
'w:lsdException': createLsdException("toc 5", 39, undefined, 1, 1) },
}, { ],
'w:lsdException': createLsdException("toc 6", 39, undefined, 1, 1) },
}, { ],
'w:lsdException': createLsdException("toc 7", 39, undefined, 1, 1) },
}, { {
'w:lsdException': createLsdException("toc 8", 39, undefined, 1, 1) "w:pPrDefault": [
}, { {
'w:lsdException': createLsdException("toc 9", 39, undefined, 1, 1) "w:pPr": [
}, { {
'w:lsdException': createLsdException("Normal Indent", undefined, undefined, 1, 1) "w:spacing": [
}, { {
'w:lsdException': createLsdException("footnote text", undefined, undefined, 1, 1) _attr: {
}] "w:after": "160",
}] "w:line": "259",
"w:lineRule": "auto",
},
},
],
},
],
},
],
},
],
},
{
"w:latentStyles": [
{
_attr: {
"w:defLockedState": "0",
"w:defUIPriority": "99",
"w:defSemiHidden": "0",
"w:defUnhideWhenUsed": "0",
"w:defQFormat": "0",
"w:count": "371",
},
},
{
"w:lsdException": createLsdException("Normal", 0, 1),
},
{
"w:lsdException": createLsdException("heading 1", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 2", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 3", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 4", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 5", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 6", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 7", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 8", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("heading 9", 9, 1, 1, 1),
},
{
"w:lsdException": createLsdException("index 1", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 2", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 3", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 4", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 5", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 6", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 7", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 8", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("index 9", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 1", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 2", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 3", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 4", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 5", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 6", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 7", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 8", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("toc 9", 39, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("Normal Indent", undefined, undefined, 1, 1),
},
{
"w:lsdException": createLsdException("footnote text", undefined, undefined, 1, 1),
},
],
},
],
}; };
return style; return style;
}; }

View File

@ -5,69 +5,55 @@ interface IComponentAttributes {
} }
class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> { class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> {
protected xmlKeys = {val: "w:val"}; protected xmlKeys = { val: "w:val" };
} }
export class Name extends XmlComponent { export class Name extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:name"); super("w:name");
this.root.push(new ComponentAttributes({val: value})); this.root.push(new ComponentAttributes({ val: value }));
} }
} }
export class BasedOn extends XmlComponent { export class BasedOn extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:basedOn"); super("w:basedOn");
this.root.push(new ComponentAttributes({val: value})); this.root.push(new ComponentAttributes({ val: value }));
} }
} }
export class Next extends XmlComponent { export class Next extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:next"); super("w:next");
this.root.push(new ComponentAttributes({val: value})); this.root.push(new ComponentAttributes({ val: value }));
} }
} }
export class Link extends XmlComponent { export class Link extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:link"); super("w:link");
this.root.push(new ComponentAttributes({val: value})); this.root.push(new ComponentAttributes({ val: value }));
} }
} }
export class UiPriority extends XmlComponent { export class UiPriority extends XmlComponent {
constructor(value: string) { constructor(value: string) {
super("w:uiPriority"); super("w:uiPriority");
// TODO: this value should be a ST_DecimalNumber // TODO: this value should be a ST_DecimalNumber
this.root.push(new ComponentAttributes({val: value})); this.root.push(new ComponentAttributes({ val: value }));
} }
} }
export class UnhideWhenUsed extends XmlComponent { export class UnhideWhenUsed extends XmlComponent {}
}
export class QuickFormat extends XmlComponent { export class QuickFormat extends XmlComponent {
constructor() { constructor() {
super("w:qFormat"); super("w:qFormat");
} }
} }
export class TableProperties extends XmlComponent { export class TableProperties extends XmlComponent {}
} export class RsId extends XmlComponent {}
export class RsId extends XmlComponent { export class SemiHidden extends XmlComponent {}
}
export class SemiHidden extends XmlComponent {
}

View File

@ -22,7 +22,6 @@ class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> {
} }
export class Style extends XmlComponent { export class Style extends XmlComponent {
constructor(attributes: IStyleAttributes, name?: string) { constructor(attributes: IStyleAttributes, name?: string) {
super("w:style"); super("w:style");
this.root.push(new StyleAttributes(attributes)); this.root.push(new StyleAttributes(attributes));
@ -37,12 +36,11 @@ export class Style extends XmlComponent {
} }
export class ParagraphStyle extends Style { export class ParagraphStyle extends Style {
private paragraphProperties: paragraph.ParagraphProperties; private paragraphProperties: paragraph.ParagraphProperties;
private runProperties: RunProperties; private runProperties: RunProperties;
constructor(styleId: string, name?: string) { constructor(styleId: string, name?: string) {
super({type: "paragraph", styleId: styleId}, name); super({ type: "paragraph", styleId: styleId }, name);
this.paragraphProperties = new paragraph.ParagraphProperties(); this.paragraphProperties = new paragraph.ParagraphProperties();
this.runProperties = new RunProperties(); this.runProperties = new RunProperties();
this.root.push(this.paragraphProperties); this.root.push(this.paragraphProperties);
@ -193,7 +191,6 @@ export class ParagraphStyle extends Style {
} }
export class HeadingStyle extends ParagraphStyle { export class HeadingStyle extends ParagraphStyle {
constructor(styleId: string, name: string) { constructor(styleId: string, name: string) {
super(styleId, name); super(styleId, name);
this.basedOn("Normal"); this.basedOn("Normal");
@ -203,56 +200,48 @@ export class HeadingStyle extends ParagraphStyle {
} }
export class TitleStyle extends HeadingStyle { export class TitleStyle extends HeadingStyle {
constructor() { constructor() {
super("Title", "Title"); super("Title", "Title");
} }
} }
export class Heading1Style extends HeadingStyle { export class Heading1Style extends HeadingStyle {
constructor() { constructor() {
super("Heading1", "Heading 1"); super("Heading1", "Heading 1");
} }
} }
export class Heading2Style extends HeadingStyle { export class Heading2Style extends HeadingStyle {
constructor() { constructor() {
super("Heading2", "Heading 2"); super("Heading2", "Heading 2");
} }
} }
export class Heading3Style extends HeadingStyle { export class Heading3Style extends HeadingStyle {
constructor() { constructor() {
super("Heading3", "Heading 3"); super("Heading3", "Heading 3");
} }
} }
export class Heading4Style extends HeadingStyle { export class Heading4Style extends HeadingStyle {
constructor() { constructor() {
super("Heading4", "Heading 4"); super("Heading4", "Heading 4");
} }
} }
export class Heading5Style extends HeadingStyle { export class Heading5Style extends HeadingStyle {
constructor() { constructor() {
super("Heading5", "Heading 5"); super("Heading5", "Heading 5");
} }
} }
export class Heading6Style extends HeadingStyle { export class Heading6Style extends HeadingStyle {
constructor() { constructor() {
super("Heading6", "Heading 6"); super("Heading6", "Heading 6");
} }
} }
export class ListParagraph extends ParagraphStyle { export class ListParagraph extends ParagraphStyle {
constructor() { constructor() {
super("ListParagraph"); super("ListParagraph");
this.root.push(new Name("List Paragraph")); this.root.push(new Name("List Paragraph"));

View File

@ -22,26 +22,26 @@ describe("Styles", () => {
it("should create a new paragraph style and push it onto this collection", () => { it("should create a new paragraph style and push it onto this collection", () => {
styles.createParagraphStyle("pStyleId"); styles.createParagraphStyle("pStyleId");
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr); const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
expect(tree).to.deep.equal([{ expect(tree).to.deep.equal([
"w:style": [ {
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
{"w:pPr": []}, },
{"w:rPr": []}, ]);
],
}]);
}); });
it("should set the paragraph name if given", () => { it("should set the paragraph name if given", () => {
styles.createParagraphStyle("pStyleId", "Paragraph Style"); styles.createParagraphStyle("pStyleId", "Paragraph Style");
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr); const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
expect(tree).to.deep.equal([{ expect(tree).to.deep.equal([
"w:style": [ {
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}}, "w:style": [
{"w:name": [{_attr: {"w:val": "Paragraph Style"}}]}, { _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } },
{"w:pPr": []}, { "w:name": [{ _attr: { "w:val": "Paragraph Style" } }] },
{"w:rPr": []}, { "w:pPr": [] },
], { "w:rPr": [] },
}]); ],
},
]);
}); });
}); });
}); });
@ -56,22 +56,23 @@ describe("Style", () => {
}); });
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": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } }],
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true}},
],
}); });
}); });
it("should set the name of the style, if given", () => { it("should set the name of the style, if given", () => {
const style = new Style({ const style = new Style(
type: "paragraph", {
styleId: "myStyleId", type: "paragraph",
}, "Style Name"); styleId: "myStyleId",
},
"Style Name",
);
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:name": [{_attr: {"w:val": "Style Name"}}]}, { "w:name": [{ _attr: { "w:val": "Style Name" } }] },
], ],
}); });
}); });
@ -82,31 +83,31 @@ describe("Style components", () => {
it("Name#constructor", () => { it("Name#constructor", () => {
const style = new components.Name("Style Name"); const style = new components.Name("Style Name");
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({"w:name": [{_attr: {"w:val": "Style Name"}}]}); expect(tree).to.deep.equal({ "w:name": [{ _attr: { "w:val": "Style Name" } }] });
}); });
it("BasedOn#constructor", () => { it("BasedOn#constructor", () => {
const style = new components.BasedOn("otherId"); const style = new components.BasedOn("otherId");
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({"w:basedOn": [{_attr: {"w:val": "otherId"}}]}); expect(tree).to.deep.equal({ "w:basedOn": [{ _attr: { "w:val": "otherId" } }] });
}); });
it("Next#constructor", () => { it("Next#constructor", () => {
const style = new components.Next("otherId"); const style = new components.Next("otherId");
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({"w:next": [{_attr: {"w:val": "otherId"}}]}); expect(tree).to.deep.equal({ "w:next": [{ _attr: { "w:val": "otherId" } }] });
}); });
it("Link#constructor", () => { it("Link#constructor", () => {
const style = new components.Link("otherId"); const style = new components.Link("otherId");
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({"w:link": [{_attr: {"w:val": "otherId"}}]}); expect(tree).to.deep.equal({ "w:link": [{ _attr: { "w:val": "otherId" } }] });
}); });
it("UiPriority#constructor", () => { it("UiPriority#constructor", () => {
const style = new components.UiPriority("123"); const style = new components.UiPriority("123");
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({"w:uiPriority": [{_attr: {"w:val": "123"}}]}); expect(tree).to.deep.equal({ "w:uiPriority": [{ _attr: { "w:val": "123" } }] });
}); });
}); });
@ -116,11 +117,7 @@ describe("ParagraphStyle", () => {
const style = new ParagraphStyle("myStyleId"); const style = new ParagraphStyle("myStyleId");
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": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": []},
{"w:rPr": []},
],
}); });
}); });
@ -129,10 +126,10 @@ describe("ParagraphStyle", () => {
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:name": [{_attr: {"w:val": "Style Name"}}]}, { "w:name": [{ _attr: { "w:val": "Style Name" } }] },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
@ -140,43 +137,40 @@ describe("ParagraphStyle", () => {
describe("formatting methods: style attributes", () => { describe("formatting methods: style attributes", () => {
it("#basedOn", () => { it("#basedOn", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").basedOn("otherId");
.basedOn("otherId");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": []}, { "w:rPr": [] },
{"w:basedOn": [{_attr: {"w:val": "otherId"}}]}, { "w:basedOn": [{ _attr: { "w:val": "otherId" } }] },
], ],
}); });
}); });
it("#quickFormat", () => { it("#quickFormat", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").quickFormat();
.quickFormat();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": []}, { "w:rPr": [] },
{"w:qFormat": []}, { "w:qFormat": [] },
], ],
}); });
}); });
it("#next", () => { it("#next", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").next("otherId");
.next("otherId");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": []}, { "w:rPr": [] },
{"w:next": [{_attr: {"w:val": "otherId"}}]}, { "w:next": [{ _attr: { "w:val": "otherId" } }] },
], ],
}); });
}); });
@ -184,171 +178,176 @@ 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({ left: 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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:ind": [{_attr: {"w:left": 720}}]}, "w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#spacing", () => { it("#spacing", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").spacing({ before: 50, after: 150 });
.spacing({before: 50, after: 150});
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:spacing": [{_attr: {"w:before": 50, "w:after": 150}}]}, "w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 50, "w:after": 150 } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#center", () => { it("#center", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").center();
.center();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:jc": [{_attr: {"w:val": "center"}}]}, "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#left", () => { it("#left", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").left();
.left();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:jc": [{_attr: {"w:val": "left"}}]}, "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#right", () => { it("#right", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").right();
.right();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:jc": [{_attr: {"w:val": "right"}}]}, "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#justified", () => { it("#justified", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").justified();
.justified();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:jc": [{_attr: {"w:val": "both"}}]}, "w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
]}, },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#thematicBreak", () => { it("#thematicBreak", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").thematicBreak();
.thematicBreak();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:pBdr": [{"w:bottom": [{_attr: { "w:pPr": [
"w:color": "auto", {
"w:space": "1", "w:pBdr": [
"w:val": "single", {
"w:sz": "6", "w:bottom": [
}}]}]}, {
]}, _attr: {
{"w:rPr": []}, "w:color": "auto",
"w:space": "1",
"w:val": "single",
"w:sz": "6",
},
},
],
},
],
},
],
},
{ "w:rPr": [] },
], ],
}); });
}); });
it("#leftTabStop", () => { it("#leftTabStop", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").leftTabStop(1200);
.leftTabStop(1200);
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:tabs": [ "w:pPr": [
{"w:tab": [{_attr: {"w:val": "left", "w:pos": 1200}}]}, {
]}, "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }],
]}, },
{"w:rPr": []}, ],
},
{ "w:rPr": [] },
], ],
}); });
}); });
it("#maxRightTabStop", () => { it("#maxRightTabStop", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").maxRightTabStop();
.maxRightTabStop();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [ {
{"w:tabs": [ "w:pPr": [
{"w:tab": [{_attr: {"w:val": "right", "w:pos": 9026}}]}, {
]}, "w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }],
]}, },
{"w:rPr": []}, ],
},
{ "w:rPr": [] },
], ],
}); });
}); });
it("#keepLines", () => { it("#keepLines", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").keepLines();
.keepLines();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [{"w:keepLines": []}]}, { "w:pPr": [{ "w:keepLines": [] }] },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
it("#keepNext", () => { it("#keepNext", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").keepNext();
.keepNext();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [{"w:keepNext": []}]}, { "w:pPr": [{ "w:keepNext": [] }] },
{"w:rPr": []}, { "w:rPr": [] },
], ],
}); });
}); });
@ -356,211 +355,197 @@ describe("ParagraphStyle", () => {
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { it("#size", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").size(24);
.size(24);
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:sz": [{_attr: {"w:val": 24}}]}, "w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }],
]}, },
], ],
}); });
}); });
it("#smallCaps", () => { it("#smallCaps", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").smallCaps();
.smallCaps();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:smallCaps": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
it("#allCaps", () => { it("#allCaps", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").allCaps();
.allCaps();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:caps": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
it("#strike", () => { it("#strike", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").strike();
.strike();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:strike": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
it("#doubleStrike", () => { it("#doubleStrike", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").doubleStrike();
.doubleStrike();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:dstrike": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
it("#subScript", () => { it("#subScript", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").subScript();
.subScript();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:vertAlign": [{_attr: {"w:val": "subscript"}}]}, "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }],
]}, },
], ],
}); });
}); });
it("#superScript", () => { it("#superScript", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").superScript();
.superScript();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:vertAlign": [{_attr: {"w:val": "superscript"}}]}, "w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }],
]}, },
], ],
}); });
}); });
it("#font", () => { it("#font", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").font("Times");
.font("Times");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]}, { "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] },
], ],
}); });
}); });
it("#bold", () => { it("#bold", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").bold();
.bold();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:b": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
it("#italics", () => { it("#italics", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").italics();
.italics();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:i": [{_attr: {"w:val": true}}]}, "w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
]}, },
], ],
}); });
}); });
describe("#underline", () => { describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => { it("should set underline to 'single' if no arguments are given", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").underline();
.underline();
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:u": [{_attr: {"w:val": "single"}}]}, "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }],
]}, },
], ],
}); });
}); });
it("should set the style if given", () => { it("should set the style if given", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").underline("double");
.underline("double");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:u": [{_attr: {"w:val": "double"}}]}, "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double" } }] }],
]}, },
], ],
}); });
}); });
it("should set the style and color if given", () => { it("should set the style and color if given", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").underline("double", "005599");
.underline("double", "005599");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:u": [{_attr: {"w:val": "double", "w:color": "005599"}}]}, "w:rPr": [{ "w:u": [{ _attr: { "w:val": "double", "w:color": "005599" } }] }],
]}, },
], ],
}); });
}); });
}); });
it("#color", () => { it("#color", () => {
const style = new ParagraphStyle("myStyleId") const style = new ParagraphStyle("myStyleId").color("123456");
.color("123456");
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": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": []}, { "w:pPr": [] },
{"w:rPr": [ {
{"w:color": [{_attr: {"w:val": "123456"}}]}, "w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
]}, },
], ],
}); });
}); });

View File

@ -9,14 +9,14 @@ describe("GridCol", () => {
const grid = new GridCol(1234); const grid = new GridCol(1234);
const tree = new Formatter().format(grid); const tree = new Formatter().format(grid);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:gridCol": [{_attr: {"w:w": 1234}}], "w:gridCol": [{ _attr: { "w:w": 1234 } }],
}); });
}); });
it("does not set a width attribute if not given", () => { it("does not set a width attribute if not given", () => {
const grid = new GridCol(); const grid = new GridCol();
const tree = new Formatter().format(grid); const tree = new Formatter().format(grid);
expect(tree).to.deep.equal({"w:gridCol": []}); expect(tree).to.deep.equal({ "w:gridCol": [] });
}); });
}); });
}); });
@ -28,9 +28,9 @@ describe("TableGrid", () => {
const tree = new Formatter().format(grid); const tree = new Formatter().format(grid);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tblGrid": [ "w:tblGrid": [
{"w:gridCol": [{_attr: {"w:w": 1234}}]}, { "w:gridCol": [{ _attr: { "w:w": 1234 } }] },
{"w:gridCol": [{_attr: {"w:w": 321}}]}, { "w:gridCol": [{ _attr: { "w:w": 321 } }] },
{"w:gridCol": [{_attr: {"w:w": 123}}]}, { "w:gridCol": [{ _attr: { "w:w": 123 } }] },
], ],
}); });
}); });

View File

@ -7,15 +7,15 @@ export class TableGrid extends XmlComponent {
} }
} }
class GridColAttributes extends XmlAttributeComponent<{w: number}> { class GridColAttributes extends XmlAttributeComponent<{ w: number }> {
protected xmlKeys = {w: "w:w"}; protected xmlKeys = { w: "w:w" };
} }
export class GridCol extends XmlComponent { export class GridCol extends XmlComponent {
constructor(width?: number) { constructor(width?: number) {
super("w:gridCol"); super("w:gridCol");
if (width !== undefined) { if (width !== undefined) {
this.root.push(new GridColAttributes({w: width})); this.root.push(new GridColAttributes({ w: width }));
} }
} }
} }

View File

@ -8,7 +8,7 @@ describe("TableProperties", () => {
it("creates an initially empty property object", () => { it("creates an initially empty property object", () => {
const tp = new TableProperties(); const tp = new TableProperties();
const tree = new Formatter().format(tp); const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({"w:tblPr": []}); expect(tree).to.deep.equal({ "w:tblPr": [] });
}); });
}); });
@ -17,9 +17,7 @@ describe("TableProperties", () => {
const tp = new TableProperties().setWidth("dxa", 1234); const tp = new TableProperties().setWidth("dxa", 1234);
const tree = new Formatter().format(tp); const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tblPr": [ "w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "dxa", "w:w": 1234 } }] }],
{"w:tblW": [{_attr: {"w:type": "dxa", "w:w": 1234}}]},
],
}); });
}); });
}); });
@ -29,9 +27,7 @@ describe("TableProperties", () => {
const tp = new TableProperties().fixedWidthLayout(); const tp = new TableProperties().fixedWidthLayout();
const tree = new Formatter().format(tp); const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tblPr": [ "w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
],
}); });
}); });
}); });

View File

@ -24,25 +24,25 @@ interface ITableWidth {
} }
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> { class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
protected xmlKeys = {type: "w:type", w: "w:w"}; protected xmlKeys = { type: "w:type", w: "w:w" };
} }
class PreferredTableWidth extends XmlComponent { class PreferredTableWidth extends XmlComponent {
constructor(type: WidthTypes, w: number | string) { constructor(type: WidthTypes, w: number | string) {
super("w:tblW"); super("w:tblW");
this.root.push(new TableWidthAttributes({type, w})); this.root.push(new TableWidthAttributes({ type, w }));
} }
} }
type TableLayoutOptions = "autofit" | "fixed"; type TableLayoutOptions = "autofit" | "fixed";
class TableLayoutAttributes extends XmlAttributeComponent<{type: TableLayoutOptions}> { class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutOptions }> {
protected xmlKeys = {type: "w:type"}; protected xmlKeys = { type: "w:type" };
} }
class TableLayout extends XmlComponent { class TableLayout extends XmlComponent {
constructor(type: TableLayoutOptions) { constructor(type: TableLayoutOptions) {
super("w:tblLayout"); super("w:tblLayout");
this.root.push(new TableLayoutAttributes({type})); this.root.push(new TableLayoutAttributes({ type }));
} }
} }

View File

@ -10,17 +10,16 @@ describe("Table", () => {
it("creates a table with the correct number of rows and columns", () => { it("creates a table with the correct number of rows and columns", () => {
const table = new Table(3, 2); const table = new Table(3, 2);
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
const cell = {"w:tc": [{"w:tcPr": []}, {"w:p": [{"w:pPr": []}]}]}; const cell = { "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }] };
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tbl": [ "w:tbl": [
{"w:tblPr": []}, { "w:tblPr": [] },
{"w:tblGrid": [ {
{"w:gridCol": [{_attr: {"w:w": 1}}]}, "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
{"w:gridCol": [{_attr: {"w:w": 1}}]}, },
]}, { "w:tr": [{ "w:trPr": [] }, cell, cell] },
{"w:tr": [{"w:trPr": []}, cell, cell]}, { "w:tr": [{ "w:trPr": [] }, cell, cell] },
{"w:tr": [{"w:trPr": []}, cell, cell]}, { "w:tr": [{ "w:trPr": [] }, cell, cell] },
{"w:tr": [{"w:trPr": []}, cell, cell]},
], ],
}); });
}); });
@ -29,27 +28,39 @@ describe("Table", () => {
describe("#getRow and Row#getCell", () => { describe("#getRow and Row#getCell", () => {
it("returns the correct row", () => { it("returns the correct row", () => {
const table = new Table(2, 2); const table = new Table(2, 2);
table.getRow(0).getCell(0).addContent(new Paragraph("A1")); table
table.getRow(0).getCell(1).addContent(new Paragraph("B1")); .getRow(0)
table.getRow(1).getCell(0).addContent(new Paragraph("A2")); .getCell(0)
table.getRow(1).getCell(1).addContent(new Paragraph("B2")); .addContent(new Paragraph("A1"));
table
.getRow(0)
.getCell(1)
.addContent(new Paragraph("B1"));
table
.getRow(1)
.getCell(0)
.addContent(new Paragraph("A2"));
table
.getRow(1)
.getCell(1)
.addContent(new Paragraph("B2"));
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
const cell = (c) => ({"w:tc": [ const cell = (c) => ({
{"w:tcPr": []}, "w:tc": [
{"w:p": [ { "w:tcPr": [] },
{"w:pPr": []}, {
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]}, "w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
]}, },
]}); ],
});
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tbl": [ "w:tbl": [
{"w:tblPr": []}, { "w:tblPr": [] },
{"w:tblGrid": [ {
{"w:gridCol": [{_attr: {"w:w": 1}}]}, "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
{"w:gridCol": [{_attr: {"w:w": 1}}]}, },
]}, { "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
{"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]}, { "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
{"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]},
], ],
}); });
}); });
@ -63,22 +74,22 @@ describe("Table", () => {
table.getCell(1, 0).addContent(new Paragraph("A2")); table.getCell(1, 0).addContent(new Paragraph("A2"));
table.getCell(1, 1).addContent(new Paragraph("B2")); table.getCell(1, 1).addContent(new Paragraph("B2"));
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
const cell = (c) => ({"w:tc": [ const cell = (c) => ({
{"w:tcPr": []}, "w:tc": [
{"w:p": [ { "w:tcPr": [] },
{"w:pPr": []}, {
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, c]}]}, "w:p": [{ "w:pPr": [] }, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, c] }] }],
]}, },
]}); ],
});
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:tbl": [ "w:tbl": [
{"w:tblPr": []}, { "w:tblPr": [] },
{"w:tblGrid": [ {
{"w:gridCol": [{_attr: {"w:w": 1}}]}, "w:tblGrid": [{ "w:gridCol": [{ _attr: { "w:w": 1 } }] }, { "w:gridCol": [{ _attr: { "w:w": 1 } }] }],
{"w:gridCol": [{_attr: {"w:w": 1}}]}, },
]}, { "w:tr": [{ "w:trPr": [] }, cell("A1"), cell("B1")] },
{"w:tr": [{"w:trPr": []}, cell("A1"), cell("B1")]}, { "w:tr": [{ "w:trPr": [] }, cell("A2"), cell("B2")] },
{"w:tr": [{"w:trPr": []}, cell("A2"), cell("B2")]},
], ],
}); });
}); });
@ -88,11 +99,12 @@ describe("Table", () => {
it("sets the preferred width on the table", () => { it("sets the preferred width on the table", () => {
const table = new Table(2, 2).setWidth("pct", 1000); const table = new Table(2, 2).setWidth("pct", 1000);
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({ expect(tree["w:tbl"][0]).to.deep.equal({
"w:tblPr": [ "w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }],
{"w:tblW": [{_attr: {"w:type": "pct", "w:w": 1000}}]},
],
}); });
}); });
}); });
@ -101,11 +113,12 @@ describe("Table", () => {
it("sets the table to fixed width layout", () => { it("sets the table to fixed width layout", () => {
const table = new Table(2, 2).fixedWidthLayout(); const table = new Table(2, 2).fixedWidthLayout();
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array")
.with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({ expect(tree["w:tbl"][0]).to.deep.equal({
"w:tblPr": [ "w:tblPr": [{ "w:tblLayout": [{ _attr: { "w:type": "fixed" } }] }],
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
],
}); });
}); });
}); });
@ -115,15 +128,16 @@ describe("Table", () => {
it("inserts a paragraph at the end of the cell if it is empty", () => { it("inserts a paragraph at the end of the cell if it is empty", () => {
const table = new Table(1, 1); const table = new Table(1, 1);
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array"); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]); const row = tree["w:tbl"].find((x) => x["w:tr"]);
expect(row).not.to.be.undefined; expect(row).not.to.be.undefined;
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); expect(row["w:tr"])
.to.be.an("array")
.which.has.length.at.least(1);
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
"w:tc": [ "w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }],
{"w:tcPr": []},
{"w:p": [{"w:pPr": []}]},
],
}); });
}); });
@ -131,14 +145,18 @@ describe("Table", () => {
const parentTable = new Table(1, 1); const parentTable = new Table(1, 1);
parentTable.getCell(0, 0).addContent(new Table(1, 1)); parentTable.getCell(0, 0).addContent(new Table(1, 1));
const tree = new Formatter().format(parentTable); const tree = new Formatter().format(parentTable);
expect(tree).to.have.property("w:tbl").which.is.an("array"); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]); const row = tree["w:tbl"].find((x) => x["w:tr"]);
expect(row).not.to.be.undefined; expect(row).not.to.be.undefined;
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); expect(row["w:tr"])
.to.be.an("array")
.which.has.length.at.least(1);
const cell = row["w:tr"].find((x) => x["w:tc"]); const cell = row["w:tr"].find((x) => x["w:tc"]);
expect(cell).not.to.be.undefined; expect(cell).not.to.be.undefined;
expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({ expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({
"w:p": [{"w:pPr": []}], "w:p": [{ "w:pPr": [] }],
}); });
}); });
@ -146,17 +164,23 @@ describe("Table", () => {
const parentTable = new Table(1, 1); const parentTable = new Table(1, 1);
parentTable.getCell(0, 0).addContent(new Paragraph("Hello")); parentTable.getCell(0, 0).addContent(new Paragraph("Hello"));
const tree = new Formatter().format(parentTable); const tree = new Formatter().format(parentTable);
expect(tree).to.have.property("w:tbl").which.is.an("array"); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]); const row = tree["w:tbl"].find((x) => x["w:tr"]);
expect(row).not.to.be.undefined; expect(row).not.to.be.undefined;
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); expect(row["w:tr"])
.to.be.an("array")
.which.has.length.at.least(1);
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
"w:tc": [ "w:tc": [
{"w:tcPr": []}, { "w:tcPr": [] },
{"w:p": [ {
{"w:pPr": []}, "w:p": [
{"w:r": [{"w:rPr": []}, {"w:t": [{_attr: {"xml:space": "preserve"}}, "Hello"]}]}, { "w:pPr": [] },
]}, { "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Hello"] }] },
],
},
], ],
}); });
}); });
@ -168,20 +192,25 @@ describe("Table", () => {
const para = table.getCell(0, 0).createParagraph("Test paragraph"); const para = table.getCell(0, 0).createParagraph("Test paragraph");
expect(para).to.be.an.instanceof(Paragraph); expect(para).to.be.an.instanceof(Paragraph);
const tree = new Formatter().format(table); const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array"); expect(tree)
.to.have.property("w:tbl")
.which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]); const row = tree["w:tbl"].find((x) => x["w:tr"]);
expect(row).not.to.be.undefined; expect(row).not.to.be.undefined;
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1); expect(row["w:tr"])
.to.be.an("array")
.which.has.length.at.least(1);
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({ expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
"w:tc": [ "w:tc": [
{"w:tcPr": []}, { "w:tcPr": [] },
{"w:p": [ {
{"w:pPr": []}, "w:p": [
{"w:r": [ { "w:pPr": [] },
{"w:rPr": []}, {
{"w:t": [{_attr: {"xml:space": "preserve"}}, "Test paragraph"]}, "w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "Test paragraph"] }],
]}, },
]}, ],
},
], ],
}); });
}); });

View File

@ -4,7 +4,6 @@ import { Attributes } from "./";
describe("Attribute", () => { describe("Attribute", () => {
describe("#constructor()", () => { describe("#constructor()", () => {
it("should have val as defined with populated constructor", () => { it("should have val as defined with populated constructor", () => {
const newAttrs = new Attributes({ const newAttrs = new Attributes({
val: "test", val: "test",

View File

@ -1,7 +1,7 @@
import { BaseXmlComponent } from "./base"; import { BaseXmlComponent } from "./base";
import { IXmlableObject } from "./xmlable-object"; import { IXmlableObject } from "./xmlable-object";
export type AttributeMap<T> = {[P in keyof T]: string}; export type AttributeMap<T> = { [P in keyof T]: string };
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent { export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
protected root: T; protected root: T;
@ -21,6 +21,6 @@ export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
attrs[newKey] = value; attrs[newKey] = value;
} }
}); });
return {_attr: attrs}; return { _attr: attrs };
} }
} }

View File

@ -3,9 +3,7 @@ import { assert } from "chai";
import { Utility } from "../../tests/utility"; import { Utility } from "../../tests/utility";
import { XmlComponent } from "./"; import { XmlComponent } from "./";
class TestComponent extends XmlComponent { class TestComponent extends XmlComponent {}
}
describe("XmlComponent", () => { describe("XmlComponent", () => {
let xmlComponent: TestComponent; let xmlComponent: TestComponent;
@ -15,7 +13,6 @@ describe("XmlComponent", () => {
}); });
describe("#constructor()", () => { describe("#constructor()", () => {
it("should create an Xml Component which has the correct rootKey", () => { it("should create an Xml Component which has the correct rootKey", () => {
const newJson = Utility.jsonify(xmlComponent); const newJson = Utility.jsonify(xmlComponent);
assert.equal(newJson.rootKey, "w:test"); assert.equal(newJson.rootKey, "w:test");

View File

@ -11,12 +11,14 @@ export abstract class XmlComponent extends BaseXmlComponent {
} }
public prepForXml(): IXmlableObject { public prepForXml(): IXmlableObject {
const children = this.root.map((comp) => { const children = this.root
if (comp instanceof BaseXmlComponent) { .map((comp) => {
return comp.prepForXml(); if (comp instanceof BaseXmlComponent) {
} return comp.prepForXml();
return comp; }
}).filter((comp) => comp); // Exclude null, undefined, and empty strings return comp;
})
.filter((comp) => comp); // Exclude null, undefined, and empty strings
return { return {
[this.rootKey]: children, [this.rootKey]: children,
}; };

Some files were not shown because too many files have changed in this diff Show More