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();
});
});
}
}

View File

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

View File

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

View File

@ -13,21 +13,22 @@ export class PdfConvertWrapper {
url: "http://mirror1.convertonlinefree.com",
encoding: null,
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: {
"__EVENTTARGET": "",
"__EVENTARGUMENT": "",
"__VIEWSTATE": "",
"ctl00$MainContent$fu": {
__EVENTTARGET: "",
__EVENTARGUMENT: "",
__VIEWSTATE: "",
ctl00$MainContent$fu: {
value: fs.readFileSync(filePath),
options: {
filename: "output.docx",
contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
},
},
"ctl00$MainContent$btnConvert": "Convert",
"ctl00$MainContent$fuZip": "",
ctl00$MainContent$btnConvert: "Convert",
ctl00$MainContent$fuZip: "",
},
});
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,8 @@ export class Document extends XmlComponent {
constructor() {
super("w:document");
this.root.push(new DocumentAttributes({
this.root.push(
new DocumentAttributes({
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
o: "urn:schemas-microsoft-com:office:office",
@ -29,7 +30,8 @@ export class Document extends XmlComponent {
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14",
}));
}),
);
this.body = new Body();
this.root.push(this.body);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -2,13 +2,14 @@ import { XmlComponent } from "file/xml-components";
import { GraphicFrameLockAttributes } from "./graphic-frame-lock-attributes";
export class GraphicFrameLocks extends XmlComponent {
constructor() {
super("a:graphicFrameLocks");
this.root.push(new GraphicFrameLockAttributes({
this.root.push(
new GraphicFrameLockAttributes({
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";
export class GraphicFrameProperties extends XmlComponent {
constructor() {
super("wp:cNvGraphicFramePr");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,12 +2,13 @@ import { XmlComponent } from "file/xml-components";
import { PicLocksAttributes } from "./pic-locks-attributes";
export class PicLocks extends XmlComponent {
constructor() {
super("a:picLocks");
this.root.push(new PicLocksAttributes({
this.root.push(
new PicLocksAttributes({
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";
export class NonVisualPicProperties extends XmlComponent {
constructor() {
super("pic:nvPicPr");
this.root.push(new NonVisualProperties());
this.root.push(new ChildNonVisualProperties());
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,12 +12,13 @@ class GraphicAttributes extends XmlAttributeComponent<IGraphicProperties> {
}
export class Graphic extends XmlComponent {
constructor(referenceId: number, x: number, y: number) {
super("a:graphic");
this.root.push(new GraphicAttributes({
this.root.push(
new GraphicAttributes({
a: "http://schemas.openxmlformats.org/drawingml/2006/main",
}));
}),
);
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";
export class Inline extends XmlComponent {
constructor(referenceId: number, dimensions: IMediaDataDimensions) {
super("wp:inline");
this.root.push(new InlineAttributes({
this.root.push(
new InlineAttributes({
distT: 0,
distB: 0,
distL: 0,
distR: 0,
}));
}),
);
this.root.push(new Extent(dimensions.emus.x, dimensions.emus.y));
this.root.push(new EffectExtent());

View File

@ -9,7 +9,6 @@ import { DefaultStylesFactory } from "./styles/factory";
import { Table } from "./table";
export class File {
private document: Document;
private styles: Styles;
private properties: Properties;
@ -54,7 +53,11 @@ export class File {
public createImage(image: string): void {
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);
}

View File

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

View File

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

View File

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

View File

@ -2,12 +2,13 @@ import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-compon
import { LevelForOverride } from "./level";
class AbstractNumId extends XmlComponent {
constructor(value: number) {
super("w:abstractNumId");
this.root.push(new Attributes({
this.root.push(
new Attributes({
val: value,
}));
}),
);
}
}
@ -24,9 +25,11 @@ export class Num extends XmlComponent {
constructor(numId: number, abstractNumId: number) {
super("w:num");
this.root.push(new NumAttributes({
this.root.push(
new NumAttributes({
numId: numId,
}));
}),
);
this.root.push(new AbstractNumId(abstractNumId));
this.id = numId;
}

View File

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

View File

@ -10,7 +10,8 @@ export class Numbering extends XmlComponent {
constructor() {
super("w:numbering");
this.root.push(new DocumentAttributes({
this.root.push(
new DocumentAttributes({
wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
mc: "http://schemas.openxmlformats.org/markup-compatibility/2006",
o: "urn:schemas-microsoft-com:office:office",
@ -28,45 +29,55 @@ export class Numbering extends XmlComponent {
wne: "http://schemas.microsoft.com/office/word/2006/wordml",
wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
Ignorable: "w14 w15 wp14",
}));
}),
);
this.nextId = 0;
const abstractNumbering = this.createAbstractNumbering();
abstractNumbering.createLevel(0, "bullet", "•", "left")
abstractNumbering
.createLevel(0, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 720, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.createLevel(1, "bullet", "o", "left")
abstractNumbering
.createLevel(1, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 1440, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.createLevel(2, "bullet", "•", "left")
abstractNumbering
.createLevel(2, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 2160, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.createLevel(3, "bullet", "•", "left")
abstractNumbering
.createLevel(3, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 2880, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.createLevel(4, "bullet", "o", "left")
abstractNumbering
.createLevel(4, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 3600, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.createLevel(5, "bullet", "•", "left")
abstractNumbering
.createLevel(5, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 4320, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));
abstractNumbering.createLevel(6, "bullet", "•", "left")
abstractNumbering
.createLevel(6, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 5040, hanging: 360 }))
.addRunProperty(new RunFonts("Symbol", "default"));
abstractNumbering.createLevel(7, "bullet", "o", "left")
abstractNumbering
.createLevel(7, "bullet", "o", "left")
.addParagraphProperty(new Indent({ left: 5760, hanging: 360 }))
.addRunProperty(new RunFonts("Courier New", "default"));
abstractNumbering.createLevel(8, "bullet", "•", "left")
abstractNumbering
.createLevel(8, "bullet", "•", "left")
.addParagraphProperty(new Indent({ left: 6480, hanging: 360 }))
.addRunProperty(new RunFonts("Wingdings", "default"));

View File

@ -8,7 +8,6 @@ export class AlignmentAttributes extends XmlAttributeComponent<{val: AlignmentOp
}
export class Alignment extends XmlComponent {
constructor(type: AlignmentOptions) {
super("w:jc");
this.root.push(new AlignmentAttributes({ val: type }));

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
export class TabStop extends XmlComponent {
constructor(tab: Tab) {
super("w:tabs");
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 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" };
}
export class Tab extends XmlComponent {
constructor(value: TabValue, position: string | number) {
super("w:tab");
this.root.push(new TabAttributes({
this.root.push(
new TabAttributes({
val: value,
pos: position,
}));
}),
);
}
}

View File

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

View File

@ -12,7 +12,6 @@ describe("Paragraph", () => {
});
describe("#constructor()", () => {
it("should create valid JSON", () => {
const stringifiedJson = JSON.stringify(paragraph);
let newJson;
@ -37,11 +36,10 @@ describe("Paragraph", () => {
const run = paragraph.createTextRun("this is a test run");
expect(run).to.be.instanceof(file.TextRun);
const tree = new Formatter().format(paragraph)["w:p"];
expect(tree).to.be.an("array").which.includes({
"w:r": [
{"w:rPr": []},
{"w:t": [{_attr: {"xml:space": "preserve"}}, "this is a test run"]},
],
expect(tree)
.to.be.an("array")
.which.includes({
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
});
});
});
@ -121,20 +119,28 @@ describe("Paragraph", () => {
paragraph.thematicBreak();
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [{
"w:pPr": [{
"w:pBdr": [{
"w:bottom": [{
"w:p": [
{
"w:pPr": [
{
"w:pBdr": [
{
"w:bottom": [
{
_attr: {
"w:val": "single",
"w:color": "auto",
"w:space": "1",
"w:sz": "6",
},
}],
}],
}],
}],
},
],
},
],
},
],
},
],
});
});
});
@ -144,14 +150,14 @@ describe("Paragraph", () => {
paragraph.pageBreak();
const tree = new Formatter().format(paragraph);
expect(tree).to.deep.equal({
"w:p": [{
"w:p": [
{
"w:pPr": [],
}, {
"w:r": [
{"w:rPr": []},
{"w:br": [{_attr: {"w:type": "page"}}]},
},
{
"w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }],
},
],
}],
});
});
});
@ -160,8 +166,14 @@ describe("Paragraph", () => {
it("should add list paragraph style to JSON", () => {
paragraph.bullet();
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["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree)
.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({
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
});
@ -170,13 +182,16 @@ describe("Paragraph", () => {
it("it should add numbered properties", () => {
paragraph.bullet();
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["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(2);
expect(tree)
.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({
"w:numPr": [
{"w:ilvl": [{_attr: {"w:val": 0}}]},
{"w:numId": [{_attr: {"w:val": 1}}]},
],
"w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 0 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }],
});
});
});
@ -190,8 +205,14 @@ describe("Paragraph", () => {
paragraph.setNumbering(letterNumbering, 0);
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["w:p"][0]).to.have.property("w:pPr").which.is.an("array").which.has.length.at.least(1);
expect(tree)
.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({
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
});
@ -230,9 +251,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"w:pStyle": [{_attr: {"w:val": "myFancyStyle"}}]},
],
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "myFancyStyle" } }] }],
},
],
});
@ -246,9 +265,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"w:ind": [{_attr: {"w:left": 720}}]},
],
"w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
},
],
});
@ -262,9 +279,7 @@ describe("Paragraph", () => {
expect(tree).to.deep.equal({
"w:p": [
{
"w:pPr": [
{"w:spacing": [{_attr: {"w:before": 90, "w:line": 50}}]},
],
"w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 90, "w:line": 50 } }] }],
},
],
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,10 +14,9 @@ describe("Text", () => {
it("adds the passed in text to the component", () => {
const t = new Text(" this is\n text");
const f = new Formatter().format(t);
expect(f).to.deep.equal({"w:t": [
{_attr: {"xml:space": "preserve"}},
" this is\n text",
]});
expect(f).to.deep.equal({
"w:t": [{ _attr: { "xml:space": "preserve" } }, " this is\n text"],
});
});
});
});

View File

@ -4,7 +4,6 @@ import { Formatter } from "../../../export/formatter";
import { RunFonts } from "./run-fonts";
describe("RunFonts", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
const tree = new Formatter().format(new RunFonts("Times"));

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@ class StyleAttributes extends XmlAttributeComponent<{val: string}> {
}
export class Style extends XmlComponent {
constructor(styleId: string) {
super("w:rStyle");
this.root.push(new StyleAttributes({ val: styleId }));

View File

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

View File

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

View File

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

View File

@ -5,9 +5,7 @@ import { Utility } from "../../../tests/utility";
import * as u from "./underline";
describe("Underline", () => {
describe("#constructor()", () => {
it("should create a new Underline object with u:u as the rootKey", () => {
const underline = new u.Underline();
const newJson = Utility.jsonify(underline);
@ -33,7 +31,6 @@ describe("Underline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should have u:u as the rootKey", () => {
const underline = new u.DashDotDotHeavyUnderline();
@ -50,7 +47,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DashDotHeavyUnderline();
@ -61,7 +57,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DashLongHeavyUnderline();
@ -72,7 +67,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DashLongUnderline();
@ -83,7 +77,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DashUnderline();
@ -94,7 +87,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DotDashUnderline();
@ -105,7 +97,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DotDotDashUnderline();
@ -116,7 +107,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DottedHeavyUnderline();
@ -127,7 +117,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DottedUnderline();
@ -138,7 +127,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.DoubleUnderline();
@ -149,7 +137,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.SingleUnderline();
@ -160,7 +147,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.ThickUnderline();
@ -171,7 +157,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.WaveUnderline();
@ -182,7 +167,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.WavyDoubleUnderline();
@ -193,7 +177,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.WavyHeavyUnderline();
@ -204,7 +187,6 @@ describe("DashDotDotHeavyUnderline", () => {
});
describe("DashDotDotHeavyUnderline", () => {
describe("#constructor()", () => {
it("should put value in attribute", () => {
const underline = new u.WordsUnderline();

View File

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

View File

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

View File

@ -4,7 +4,6 @@ import { Formatter } from "../../export/formatter";
import { Properties } from "./properties";
describe("Properties", () => {
describe("#constructor()", () => {
it("sets the appropriate attributes on the top-level", () => {
const properties = new Properties({});
@ -28,9 +27,7 @@ describe("Properties", () => {
expect(Object.keys(tree)).to.deep.equal(["cp:coreProperties"]);
expect(tree["cp:coreProperties"]).to.be.an.instanceof(Array);
expect(Object.keys(tree["cp:coreProperties"][0])).to.deep.equal(["_attr"]);
expect(tree["cp:coreProperties"][1]).to.deep.equal(
{"dc:title": ["test document"]},
);
expect(tree["cp:coreProperties"][1]).to.deep.equal({ "dc:title": ["test document"] });
});
it("should create properties with all the attributes given", () => {
@ -60,7 +57,7 @@ describe("Properties", () => {
"dcterms:created",
"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:lastModifiedBy": ["the author"] },
{ "cp:revision": ["123"] },

View File

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

View File

@ -3,12 +3,13 @@ import { RelationshipsAttributes } from "./attributes";
import { Relationship, RelationshipType } from "./relationship/relationship";
export class Relationships extends XmlComponent {
constructor() {
super("Relationships");
this.root.push(new RelationshipsAttributes({
this.root.push(
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(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";
export class DocumentDefaults extends XmlComponent {
private runPropertiesDefaults: RunPropertiesDefaults;
private paragraphPropertiesDefaults: ParagraphPropertiesDefaults;

View File

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

View File

@ -3,12 +3,17 @@ import { Color, Italics, Size } from "../paragraph/run/formatting";
import { Styles } from "./";
// import { DocumentDefaults } from "./defaults";
import {
Heading1Style, Heading2Style, Heading3Style, Heading4Style, Heading5Style, Heading6Style,
ListParagraph, TitleStyle,
Heading1Style,
Heading2Style,
Heading3Style,
Heading4Style,
Heading5Style,
Heading6Style,
ListParagraph,
TitleStyle,
} from "./style";
export class DefaultStylesFactory {
public newInstance(): Styles {
const styles = new Styles();
styles.createDocumentDefaults();

View File

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

View File

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

View File

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

View File

@ -1,149 +1,211 @@
/* tslint:disable */
function createLsdException(name, uiPriority, qFormat?, semiHidden?, unhideWhenUsed?) {
'use strict';
"use strict";
return [{
return [
{
_attr: {
'w:name': name,
'w:uiPriority': uiPriority,
'w:qFormat': qFormat,
'w:semiHidden': semiHidden,
'w:unhideWhenUsed': unhideWhenUsed
}
}];
"w:name": name,
"w:uiPriority": uiPriority,
"w:qFormat": qFormat,
"w:semiHidden": semiHidden,
"w:unhideWhenUsed": unhideWhenUsed,
},
},
];
}
export function DefaultStyle() {
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': [{
"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': [{
"w:asciiTheme": "minorHAnsi",
"w:eastAsiaTheme": "minorHAnsi",
"w:hAnsiTheme": "minorHAnsi",
"w:cstheme": "minorBidi",
},
},
],
},
{
"w:sz": [
{
_attr: {
'w:val': "22"
}
}]
}, {
'w:szCs': [{
"w:val": "22",
},
},
],
},
{
"w:szCs": [
{
_attr: {
'w:val': "22"
}
}]
}, {
'w:lang': [{
"w:val": "22",
},
},
],
},
{
"w:lang": [
{
_attr: {
'w:val': "en-GB",
'w:eastAsia': "en-US",
'w:bidi': "ar-SA"
}
}]
}]
}]
}, {
'w:pPrDefault': [{
'w:pPr': [{
'w:spacing': [{
"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': [{
"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)
}]
}]
"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;
};
}

View File

@ -9,7 +9,6 @@ class ComponentAttributes extends XmlAttributeComponent<IComponentAttributes> {
}
export class Name extends XmlComponent {
constructor(value: string) {
super("w:name");
this.root.push(new ComponentAttributes({ val: value }));
@ -17,7 +16,6 @@ export class Name extends XmlComponent {
}
export class BasedOn extends XmlComponent {
constructor(value: string) {
super("w:basedOn");
this.root.push(new ComponentAttributes({ val: value }));
@ -25,7 +23,6 @@ export class BasedOn extends XmlComponent {
}
export class Next extends XmlComponent {
constructor(value: string) {
super("w:next");
this.root.push(new ComponentAttributes({ val: value }));
@ -33,7 +30,6 @@ export class Next extends XmlComponent {
}
export class Link extends XmlComponent {
constructor(value: string) {
super("w:link");
this.root.push(new ComponentAttributes({ val: value }));
@ -41,7 +37,6 @@ export class Link extends XmlComponent {
}
export class UiPriority extends XmlComponent {
constructor(value: string) {
super("w:uiPriority");
// TODO: this value should be a ST_DecimalNumber
@ -49,25 +44,16 @@ export class UiPriority extends XmlComponent {
}
}
export class UnhideWhenUsed extends XmlComponent {
}
export class UnhideWhenUsed extends XmlComponent {}
export class QuickFormat extends XmlComponent {
constructor() {
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 {
constructor(attributes: IStyleAttributes, name?: string) {
super("w:style");
this.root.push(new StyleAttributes(attributes));
@ -37,7 +36,6 @@ export class Style extends XmlComponent {
}
export class ParagraphStyle extends Style {
private paragraphProperties: paragraph.ParagraphProperties;
private runProperties: RunProperties;
@ -193,7 +191,6 @@ export class ParagraphStyle extends Style {
}
export class HeadingStyle extends ParagraphStyle {
constructor(styleId: string, name: string) {
super(styleId, name);
this.basedOn("Normal");
@ -203,56 +200,48 @@ export class HeadingStyle extends ParagraphStyle {
}
export class TitleStyle extends HeadingStyle {
constructor() {
super("Title", "Title");
}
}
export class Heading1Style extends HeadingStyle {
constructor() {
super("Heading1", "Heading 1");
}
}
export class Heading2Style extends HeadingStyle {
constructor() {
super("Heading2", "Heading 2");
}
}
export class Heading3Style extends HeadingStyle {
constructor() {
super("Heading3", "Heading 3");
}
}
export class Heading4Style extends HeadingStyle {
constructor() {
super("Heading4", "Heading 4");
}
}
export class Heading5Style extends HeadingStyle {
constructor() {
super("Heading5", "Heading 5");
}
}
export class Heading6Style extends HeadingStyle {
constructor() {
super("Heading6", "Heading 6");
}
}
export class ListParagraph extends ParagraphStyle {
constructor() {
super("ListParagraph");
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", () => {
styles.createParagraphStyle("pStyleId");
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
expect(tree).to.deep.equal([{
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "pStyleId"}},
{"w:pPr": []},
{"w:rPr": []},
],
}]);
expect(tree).to.deep.equal([
{
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
},
]);
});
it("should set the paragraph name if given", () => {
styles.createParagraphStyle("pStyleId", "Paragraph Style");
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:name": [{ _attr: { "w:val": "Paragraph Style" } }] },
{ "w:pPr": [] },
{ "w:rPr": [] },
],
}]);
},
]);
});
});
});
@ -56,17 +56,18 @@ describe("Style", () => {
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true}},
],
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } }],
});
});
it("should set the name of the style, if given", () => {
const style = new Style({
const style = new Style(
{
type: "paragraph",
styleId: "myStyleId",
}, "Style Name");
},
"Style Name",
);
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -116,11 +117,7 @@ describe("ParagraphStyle", () => {
const style = new ParagraphStyle("myStyleId");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}},
{"w:pPr": []},
{"w:rPr": []},
],
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, { "w:rPr": [] }],
});
});
@ -140,8 +137,7 @@ describe("ParagraphStyle", () => {
describe("formatting methods: style attributes", () => {
it("#basedOn", () => {
const style = new ParagraphStyle("myStyleId")
.basedOn("otherId");
const style = new ParagraphStyle("myStyleId").basedOn("otherId");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -154,8 +150,7 @@ describe("ParagraphStyle", () => {
});
it("#quickFormat", () => {
const style = new ParagraphStyle("myStyleId")
.quickFormat();
const style = new ParagraphStyle("myStyleId").quickFormat();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -168,8 +163,7 @@ describe("ParagraphStyle", () => {
});
it("#next", () => {
const style = new ParagraphStyle("myStyleId")
.next("otherId");
const style = new ParagraphStyle("myStyleId").next("otherId");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -184,152 +178,158 @@ describe("ParagraphStyle", () => {
describe("formatting methods: paragraph properties", () => {
it("#indent", () => {
const style = new ParagraphStyle("myStyleId")
.indent({ left: 720 });
const style = new ParagraphStyle("myStyleId").indent({ left: 720 });
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#spacing", () => {
const style = new ParagraphStyle("myStyleId")
.spacing({before: 50, after: 150});
const style = new ParagraphStyle("myStyleId").spacing({ before: 50, after: 150 });
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#center", () => {
const style = new ParagraphStyle("myStyleId")
.center();
const style = new ParagraphStyle("myStyleId").center();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#left", () => {
const style = new ParagraphStyle("myStyleId")
.left();
const style = new ParagraphStyle("myStyleId").left();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#right", () => {
const style = new ParagraphStyle("myStyleId")
.right();
const style = new ParagraphStyle("myStyleId").right();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#justified", () => {
const style = new ParagraphStyle("myStyleId")
.justified();
const style = new ParagraphStyle("myStyleId").justified();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _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": [] },
],
});
});
it("#thematicBreak", () => {
const style = new ParagraphStyle("myStyleId")
.thematicBreak();
const style = new ParagraphStyle("myStyleId").thematicBreak();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [
{"w:pBdr": [{"w:bottom": [{_attr: {
{
"w:pPr": [
{
"w:pBdr": [
{
"w:bottom": [
{
_attr: {
"w:color": "auto",
"w:space": "1",
"w:val": "single",
"w:sz": "6",
}}]}]},
]},
},
},
],
},
],
},
],
},
{ "w:rPr": [] },
],
});
});
it("#leftTabStop", () => {
const style = new ParagraphStyle("myStyleId")
.leftTabStop(1200);
const style = new ParagraphStyle("myStyleId").leftTabStop(1200);
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [
{"w:tabs": [
{"w:tab": [{_attr: {"w:val": "left", "w:pos": 1200}}]},
]},
]},
{
"w:pPr": [
{
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "left", "w:pos": 1200 } }] }],
},
],
},
{ "w:rPr": [] },
],
});
});
it("#maxRightTabStop", () => {
const style = new ParagraphStyle("myStyleId")
.maxRightTabStop();
const style = new ParagraphStyle("myStyleId").maxRightTabStop();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{"w:pPr": [
{"w:tabs": [
{"w:tab": [{_attr: {"w:val": "right", "w:pos": 9026}}]},
]},
]},
{
"w:pPr": [
{
"w:tabs": [{ "w:tab": [{ _attr: { "w:val": "right", "w:pos": 9026 } }] }],
},
],
},
{ "w:rPr": [] },
],
});
});
it("#keepLines", () => {
const style = new ParagraphStyle("myStyleId")
.keepLines();
const style = new ParagraphStyle("myStyleId").keepLines();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -341,8 +341,7 @@ describe("ParagraphStyle", () => {
});
it("#keepNext", () => {
const style = new ParagraphStyle("myStyleId")
.keepNext();
const style = new ParagraphStyle("myStyleId").keepNext();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -356,113 +355,105 @@ describe("ParagraphStyle", () => {
describe("formatting methods: run properties", () => {
it("#size", () => {
const style = new ParagraphStyle("myStyleId")
.size(24);
const style = new ParagraphStyle("myStyleId").size(24);
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:sz": [{_attr: {"w:val": 24}}]},
]},
{
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }],
},
],
});
});
it("#smallCaps", () => {
const style = new ParagraphStyle("myStyleId")
.smallCaps();
const style = new ParagraphStyle("myStyleId").smallCaps();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:smallCaps": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:smallCaps": [{ _attr: { "w:val": true } }] }],
},
],
});
});
it("#allCaps", () => {
const style = new ParagraphStyle("myStyleId")
.allCaps();
const style = new ParagraphStyle("myStyleId").allCaps();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:caps": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:caps": [{ _attr: { "w:val": true } }] }],
},
],
});
});
it("#strike", () => {
const style = new ParagraphStyle("myStyleId")
.strike();
const style = new ParagraphStyle("myStyleId").strike();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:strike": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:strike": [{ _attr: { "w:val": true } }] }],
},
],
});
});
it("#doubleStrike", () => {
const style = new ParagraphStyle("myStyleId")
.doubleStrike();
const style = new ParagraphStyle("myStyleId").doubleStrike();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:dstrike": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:dstrike": [{ _attr: { "w:val": true } }] }],
},
],
});
});
it("#subScript", () => {
const style = new ParagraphStyle("myStyleId")
.subScript();
const style = new ParagraphStyle("myStyleId").subScript();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:vertAlign": [{_attr: {"w:val": "subscript"}}]},
]},
{
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "subscript" } }] }],
},
],
});
});
it("#superScript", () => {
const style = new ParagraphStyle("myStyleId")
.superScript();
const style = new ParagraphStyle("myStyleId").superScript();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:vertAlign": [{_attr: {"w:val": "superscript"}}]},
]},
{
"w:rPr": [{ "w:vertAlign": [{ _attr: { "w:val": "superscript" } }] }],
},
],
});
});
it("#font", () => {
const style = new ParagraphStyle("myStyleId")
.font("Times");
const style = new ParagraphStyle("myStyleId").font("Times");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
@ -474,93 +465,87 @@ describe("ParagraphStyle", () => {
});
it("#bold", () => {
const style = new ParagraphStyle("myStyleId")
.bold();
const style = new ParagraphStyle("myStyleId").bold();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:b": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:b": [{ _attr: { "w:val": true } }] }],
},
],
});
});
it("#italics", () => {
const style = new ParagraphStyle("myStyleId")
.italics();
const style = new ParagraphStyle("myStyleId").italics();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:i": [{_attr: {"w:val": true}}]},
]},
{
"w:rPr": [{ "w:i": [{ _attr: { "w:val": true } }] }],
},
],
});
});
describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => {
const style = new ParagraphStyle("myStyleId")
.underline();
const style = new ParagraphStyle("myStyleId").underline();
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "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", () => {
const style = new ParagraphStyle("myStyleId")
.underline("double");
const style = new ParagraphStyle("myStyleId").underline("double");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "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", () => {
const style = new ParagraphStyle("myStyleId")
.underline("double", "005599");
const style = new ParagraphStyle("myStyleId").underline("double", "005599");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "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", () => {
const style = new ParagraphStyle("myStyleId")
.color("123456");
const style = new ParagraphStyle("myStyleId").color("123456");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{ "w:pPr": [] },
{"w:rPr": [
{"w:color": [{_attr: {"w:val": "123456"}}]},
]},
{
"w:rPr": [{ "w:color": [{ _attr: { "w:val": "123456" } }] }],
},
],
});
});

View File

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

View File

@ -14,10 +14,9 @@ describe("Table", () => {
expect(tree).to.deep.equal({
"w:tbl": [
{ "w:tblPr": [] },
{"w:tblGrid": [
{"w:gridCol": [{_attr: {"w:w": 1}}]},
{"w:gridCol": [{_attr: {"w:w": 1}}]},
]},
{
"w:tblGrid": [{ "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] },
@ -29,25 +28,37 @@ describe("Table", () => {
describe("#getRow and Row#getCell", () => {
it("returns the correct row", () => {
const table = new Table(2, 2);
table.getRow(0).getCell(0).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"));
table
.getRow(0)
.getCell(0)
.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 cell = (c) => ({"w:tc": [
const cell = (c) => ({
"w:tc": [
{ "w:tcPr": [] },
{"w:p": [
{"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({
"w:tbl": [
{ "w:tblPr": [] },
{"w:tblGrid": [
{"w:gridCol": [{_attr: {"w:w": 1}}]},
{"w:gridCol": [{_attr: {"w:w": 1}}]},
]},
{
"w:tblGrid": [{ "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("A2"), cell("B2")] },
],
@ -63,20 +74,20 @@ describe("Table", () => {
table.getCell(1, 0).addContent(new Paragraph("A2"));
table.getCell(1, 1).addContent(new Paragraph("B2"));
const tree = new Formatter().format(table);
const cell = (c) => ({"w:tc": [
const cell = (c) => ({
"w:tc": [
{ "w:tcPr": [] },
{"w:p": [
{"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({
"w:tbl": [
{ "w:tblPr": [] },
{"w:tblGrid": [
{"w:gridCol": [{_attr: {"w:w": 1}}]},
{"w:gridCol": [{_attr: {"w:w": 1}}]},
]},
{
"w:tblGrid": [{ "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("A2"), cell("B2")] },
],
@ -88,11 +99,12 @@ describe("Table", () => {
it("sets the preferred width on the table", () => {
const table = new Table(2, 2).setWidth("pct", 1000);
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({
"w:tblPr": [
{"w:tblW": [{_attr: {"w:type": "pct", "w:w": 1000}}]},
],
"w:tblPr": [{ "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }],
});
});
});
@ -101,11 +113,12 @@ describe("Table", () => {
it("sets the table to fixed width layout", () => {
const table = new Table(2, 2).fixedWidthLayout();
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({
"w:tblPr": [
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
],
"w:tblPr": [{ "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", () => {
const table = new Table(1, 1);
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"]);
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({
"w:tc": [
{"w:tcPr": []},
{"w:p": [{"w:pPr": []}]},
],
"w:tc": [{ "w:tcPr": [] }, { "w:p": [{ "w:pPr": [] }] }],
});
});
@ -131,10 +145,14 @@ describe("Table", () => {
const parentTable = new Table(1, 1);
parentTable.getCell(0, 0).addContent(new Table(1, 1));
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"]);
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"]);
expect(cell).not.to.be.undefined;
expect(cell["w:tc"][cell["w:tc"].length - 1]).to.deep.equal({
@ -146,17 +164,23 @@ describe("Table", () => {
const parentTable = new Table(1, 1);
parentTable.getCell(0, 0).addContent(new Paragraph("Hello"));
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"]);
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({
"w:tc": [
{ "w:tcPr": [] },
{"w:p": [
{
"w:p": [
{ "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");
expect(para).to.be.an.instanceof(Paragraph);
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"]);
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({
"w:tc": [
{ "w:tcPr": [] },
{"w:p": [
{
"w:p": [
{ "w:pPr": [] },
{"w:r": [
{"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("#constructor()", () => {
it("should have val as defined with populated constructor", () => {
const newAttrs = new Attributes({
val: "test",

View File

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

View File

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

View File

@ -1,3 +1,3 @@
export interface IXmlableObject extends Object {
_attr?: { [key: string]: (string | number | boolean) };
_attr?: { [key: string]: string | number | boolean };
}