Made project Prettier compliant
This commit is contained in:
@ -3,14 +3,13 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export type AlignmentOptions = "left" | "center" | "right" | "both";
|
||||
|
||||
export class AlignmentAttributes extends XmlAttributeComponent<{val: AlignmentOptions}> {
|
||||
protected xmlKeys = {val: "w:val"};
|
||||
export class AlignmentAttributes extends XmlAttributeComponent<{ val: AlignmentOptions }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Alignment extends XmlComponent {
|
||||
|
||||
constructor(type: AlignmentOptions) {
|
||||
super("w:jc");
|
||||
this.root.push(new AlignmentAttributes({val: type}));
|
||||
this.root.push(new AlignmentAttributes({ val: type }));
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,20 @@
|
||||
import { Attributes, XmlComponent } from "file/xml-components";
|
||||
|
||||
class Border extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:bottom");
|
||||
this.root.push(new Attributes({
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6",
|
||||
}));
|
||||
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());
|
||||
|
@ -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));
|
||||
|
@ -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({
|
||||
type: "page",
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
type: "page",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class PageBreak extends Run {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.root.push(new Break());
|
||||
|
@ -6,18 +6,18 @@ import { Spacing } from "./spacing";
|
||||
describe("Spacing", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the properties given", () => {
|
||||
const spacing = new Spacing({before: 100, after: 120, line: 150});
|
||||
const spacing = new Spacing({ before: 100, after: 120, line: 150 });
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:spacing": [{_attr: {"w:after": 120, "w:before": 100, "w:line": 150}}],
|
||||
"w:spacing": [{ _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } }],
|
||||
});
|
||||
});
|
||||
|
||||
it("should only set the given properties", () => {
|
||||
const spacing = new Spacing({before: 100});
|
||||
const spacing = new Spacing({ before: 100 });
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:spacing": [{_attr: {"w:before": 100}}],
|
||||
"w:spacing": [{ _attr: { "w:before": 100 } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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({
|
||||
val: type,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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}> {
|
||||
protected xmlKeys = {val: "w:val", pos: "w:pos"};
|
||||
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({
|
||||
val: value,
|
||||
pos: position,
|
||||
}));
|
||||
this.root.push(
|
||||
new TabAttributes({
|
||||
val: value,
|
||||
pos: position,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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({
|
||||
val: level,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: level,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class NumberId extends XmlComponent {
|
||||
constructor(id: number) {
|
||||
super("w:numId");
|
||||
this.root.push(new Attributes({
|
||||
val: id,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: id,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ describe("Paragraph", () => {
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
|
||||
it("should create valid JSON", () => {
|
||||
const stringifiedJson = JSON.stringify(paragraph);
|
||||
let newJson;
|
||||
@ -37,12 +36,11 @@ 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"] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -53,7 +51,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading1"}}]}],
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading1" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -67,7 +65,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading2"}}]}],
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading2" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -81,7 +79,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Heading3"}}]}],
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading3" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -95,7 +93,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{"w:pStyle": [{_attr: {"w:val": "Title"}}]}],
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Title" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -109,7 +107,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{"w:jc": [{_attr: {"w:val": "center"}}]}],
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -121,20 +119,28 @@ describe("Paragraph", () => {
|
||||
paragraph.thematicBreak();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{
|
||||
"w:pPr": [{
|
||||
"w:pBdr": [{
|
||||
"w:bottom": [{
|
||||
_attr: {
|
||||
"w:val": "single",
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
},
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
}],
|
||||
"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:pPr": [],
|
||||
}, {
|
||||
"w:r": [
|
||||
{"w:rPr": []},
|
||||
{"w:br": [{_attr: {"w:type": "page"}}]},
|
||||
],
|
||||
}],
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [],
|
||||
},
|
||||
{
|
||||
"w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -160,23 +166,32 @@ 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"}}],
|
||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
||||
});
|
||||
});
|
||||
|
||||
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,10 +205,16 @@ 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"}}],
|
||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -209,11 +230,11 @@ describe("Paragraph", () => {
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{"w:pStyle": [{_attr: {"w:val": "ListParagraph"}}]},
|
||||
{ "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }] },
|
||||
{
|
||||
"w:numPr": [
|
||||
{"w:ilvl": [{_attr: {"w:val": 0}}]},
|
||||
{"w:numId": [{_attr: {"w:val": letterNumbering.id}}]},
|
||||
{ "w:ilvl": [{ _attr: { "w:val": 0 } }] },
|
||||
{ "w:numId": [{ _attr: { "w:val": letterNumbering.id } }] },
|
||||
],
|
||||
},
|
||||
],
|
||||
@ -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 } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -257,14 +274,12 @@ describe("Paragraph", () => {
|
||||
|
||||
describe("#spacing", () => {
|
||||
it("should set the paragraph spacing to the given values", () => {
|
||||
paragraph.spacing({before: 90, line: 50});
|
||||
paragraph.spacing({ before: 90, line: 50 });
|
||||
const tree = new Formatter().format(paragraph);
|
||||
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 } }] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -276,7 +291,7 @@ describe("Paragraph", () => {
|
||||
paragraph.keepLines();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{"w:pPr": [{"w:keepLines": []}]}],
|
||||
"w:p": [{ "w:pPr": [{ "w:keepLines": [] }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -286,7 +301,7 @@ describe("Paragraph", () => {
|
||||
paragraph.keepNext();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{"w:pPr": [{"w:keepNext": []}]}],
|
||||
"w:p": [{ "w:pPr": [{ "w:keepNext": [] }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class ParagraphProperties extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:pPr");
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class Break extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:br");
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Italics extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:i");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Caps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:caps");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Color extends XmlComponent {
|
||||
|
||||
constructor(color: string) {
|
||||
super("w:color");
|
||||
this.root.push(new Attributes({
|
||||
val: color,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: color,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class DoubleStrike extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:dstrike");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Emboss extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:emboss");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Imprint extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:imprint");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Shadow extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:shadow");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SmallCaps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:smallCaps");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Strike extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:strike");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: true,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class Size extends XmlComponent {
|
||||
|
||||
constructor(size: number) {
|
||||
super("w:sz");
|
||||
this.root.push(new Attributes({
|
||||
val: size,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: size,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { IMediaData } from "../../media/data";
|
||||
import { Run } from "../run";
|
||||
|
||||
export class PictureRun extends Run {
|
||||
|
||||
constructor(imageData: IMediaData) {
|
||||
super();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class RunProperties extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:rPr");
|
||||
}
|
||||
|
@ -8,16 +8,15 @@ describe("Text", () => {
|
||||
it("creates an empty text run if no text is given", () => {
|
||||
const t = new Text("");
|
||||
const f = new Formatter().format(t);
|
||||
expect(f).to.deep.equal({"w:t": [{_attr: {"xml:space": "preserve"}}]});
|
||||
expect(f).to.deep.equal({ "w:t": [{ _attr: { "xml:space": "preserve" } }] });
|
||||
});
|
||||
|
||||
it("adds the passed in text to the component", () => {
|
||||
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"],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class TextAttributes extends XmlAttributeComponent<{space: "default" | "preserve"}> {
|
||||
protected xmlKeys = {space: "xml:space"};
|
||||
class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> {
|
||||
protected xmlKeys = { space: "xml:space" };
|
||||
}
|
||||
|
||||
export class Text extends XmlComponent {
|
||||
constructor(text: string) {
|
||||
super("w:t");
|
||||
this.root.push(new TextAttributes({space: "preserve"}));
|
||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
||||
if (text) {
|
||||
this.root.push(text);
|
||||
}
|
||||
|
@ -4,19 +4,18 @@ 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"));
|
||||
expect(tree).to.deep.equal({
|
||||
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}],
|
||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }],
|
||||
});
|
||||
});
|
||||
|
||||
it("uses hint if given", () => {
|
||||
const tree = new Formatter().format(new RunFonts("Times", "default"));
|
||||
expect(tree).to.deep.equal({
|
||||
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}],
|
||||
"w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default" } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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({
|
||||
ascii: ascii,
|
||||
hAnsi: ascii,
|
||||
hint: hint,
|
||||
}));
|
||||
this.root.push(
|
||||
new RunFontAttributes({
|
||||
ascii: ascii,
|
||||
hAnsi: ascii,
|
||||
hint: hint,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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" } }] }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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({
|
||||
val: type,
|
||||
}));
|
||||
this.root.push(
|
||||
new Attributes({
|
||||
val: type,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SuperScript extends VerticalAlign {
|
||||
|
||||
constructor() {
|
||||
super("superscript");
|
||||
}
|
||||
}
|
||||
|
||||
export class SubScript extends VerticalAlign {
|
||||
|
||||
constructor() {
|
||||
super("subscript");
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class StyleAttributes extends XmlAttributeComponent<{val: string}> {
|
||||
protected xmlKeys = {val: "w:val"};
|
||||
class StyleAttributes extends XmlAttributeComponent<{ val: string }> {
|
||||
protected xmlKeys = { val: "w:val" };
|
||||
}
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
|
||||
constructor(styleId: string) {
|
||||
super("w:rStyle");
|
||||
this.root.push(new StyleAttributes({val: styleId}));
|
||||
this.root.push(new StyleAttributes({ val: styleId }));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
|
||||
export class Tab extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:tab");
|
||||
}
|
||||
|
@ -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"] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
@ -18,7 +16,7 @@ describe("Underline", () => {
|
||||
const underline = new u.Underline();
|
||||
const tree = new Formatter().format(underline);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:u": [{_attr: {"w:val": "single"}}],
|
||||
"w:u": [{ _attr: { "w:val": "single" } }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -26,14 +24,13 @@ describe("Underline", () => {
|
||||
const underline = new u.Underline("double", "FF00CC");
|
||||
const tree = new Formatter().format(underline);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:u": [{_attr: {"w:val": "double", "w:color": "FF00CC"}}],
|
||||
"w:u": [{ _attr: { "w:val": "double", "w:color": "FF00CC" } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#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();
|
||||
|
@ -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({
|
||||
val: underlineType,
|
||||
color: color,
|
||||
}));
|
||||
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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user