Change docx folder to more appropriate "file" folder
This commit is contained in:
19
src/file/paragraph/run/break.spec.ts
Normal file
19
src/file/paragraph/run/break.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { Utility } from "../../../tests/utility";
|
||||
import { Break } from "./break";
|
||||
|
||||
describe("Break", () => {
|
||||
let currentBreak: Break;
|
||||
|
||||
beforeEach(() => {
|
||||
currentBreak = new Break();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Break with correct root key", () => {
|
||||
const newJson = Utility.jsonify(currentBreak);
|
||||
assert.equal(newJson.rootKey, "w:br");
|
||||
});
|
||||
});
|
||||
});
|
9
src/file/paragraph/run/break.ts
Normal file
9
src/file/paragraph/run/break.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// http://officeopenxml.com/WPtextSpecialContent-break.php
|
||||
import { XmlComponent } from "../../xml-components";
|
||||
|
||||
export class Break extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:br");
|
||||
}
|
||||
}
|
15
src/file/paragraph/run/caps.ts
Normal file
15
src/file/paragraph/run/caps.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { XmlComponent } from "../../xml-components";
|
||||
|
||||
export class SmallCaps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:smallCaps");
|
||||
}
|
||||
}
|
||||
|
||||
export class Caps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:caps");
|
||||
}
|
||||
}
|
114
src/file/paragraph/run/formatting.ts
Normal file
114
src/file/paragraph/run/formatting.ts
Normal file
@ -0,0 +1,114 @@
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
export { Underline } from "./underline";
|
||||
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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Italics extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:i");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Caps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:caps");
|
||||
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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class DoubleStrike extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:dstrike");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Emboss extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:emboss");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Imprint extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:imprint");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Shadow extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:shadow");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class SmallCaps extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:smallCaps");
|
||||
this.root.push(new Attributes({
|
||||
val: true,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Strike extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:strike");
|
||||
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,
|
||||
}));
|
||||
}
|
||||
}
|
3
src/file/paragraph/run/index.ts
Normal file
3
src/file/paragraph/run/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from "./run";
|
||||
export * from "./text-run";
|
||||
export * from "./picture-run";
|
16
src/file/paragraph/run/picture-run.ts
Normal file
16
src/file/paragraph/run/picture-run.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { Drawing } from "../../drawing";
|
||||
import { IData } from "../../media/data";
|
||||
import { Run } from "../run";
|
||||
|
||||
export class PictureRun extends Run {
|
||||
|
||||
constructor(imageData: IData) {
|
||||
super();
|
||||
|
||||
if (imageData === undefined) {
|
||||
throw new Error("imageData cannot be undefined");
|
||||
}
|
||||
|
||||
this.root.push(new Drawing(imageData));
|
||||
}
|
||||
}
|
12
src/file/paragraph/run/properties.ts
Normal file
12
src/file/paragraph/run/properties.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { XmlComponent } from "../../xml-components";
|
||||
|
||||
export class RunProperties extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:rPr");
|
||||
}
|
||||
|
||||
public push(item: XmlComponent): void {
|
||||
this.root.push(item);
|
||||
}
|
||||
}
|
23
src/file/paragraph/run/run-components/text.spec.ts
Normal file
23
src/file/paragraph/run/run-components/text.spec.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "../../../../export/formatter";
|
||||
import { Text } from "./text";
|
||||
|
||||
describe("Text", () => {
|
||||
describe("#constructor", () => {
|
||||
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"}}]});
|
||||
});
|
||||
|
||||
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",
|
||||
]});
|
||||
});
|
||||
});
|
||||
});
|
15
src/file/paragraph/run/run-components/text.ts
Normal file
15
src/file/paragraph/run/run-components/text.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "../../../xml-components";
|
||||
|
||||
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"}));
|
||||
if (text) {
|
||||
this.root.push(text);
|
||||
}
|
||||
}
|
||||
}
|
23
src/file/paragraph/run/run-fonts.spec.ts
Normal file
23
src/file/paragraph/run/run-fonts.spec.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
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"}}],
|
||||
});
|
||||
});
|
||||
|
||||
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"}}],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
27
src/file/paragraph/run/run-fonts.ts
Normal file
27
src/file/paragraph/run/run-fonts.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "../../xml-components";
|
||||
|
||||
interface IRunFontAttributesProperties {
|
||||
ascii: string;
|
||||
hAnsi: string;
|
||||
hint?: string;
|
||||
}
|
||||
|
||||
class RunFontAttributes extends XmlAttributeComponent<IRunFontAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
ascii: "w:ascii",
|
||||
hAnsi: "w:hAnsi",
|
||||
hint: "w:hint",
|
||||
};
|
||||
}
|
||||
|
||||
export class RunFonts extends XmlComponent {
|
||||
|
||||
constructor(ascii: string, hint?: string) {
|
||||
super("w:rFonts");
|
||||
this.root.push(new RunFontAttributes({
|
||||
ascii: ascii,
|
||||
hAnsi: ascii,
|
||||
hint: hint,
|
||||
}));
|
||||
}
|
||||
}
|
157
src/file/paragraph/run/run.spec.ts
Normal file
157
src/file/paragraph/run/run.spec.ts
Normal file
@ -0,0 +1,157 @@
|
||||
import { assert, expect } from "chai";
|
||||
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
import { Utility } from "../../../tests/utility";
|
||||
import { Run } from "./";
|
||||
|
||||
describe("Run", () => {
|
||||
let run: Run;
|
||||
|
||||
beforeEach(() => {
|
||||
run = new Run();
|
||||
});
|
||||
|
||||
describe("#bold()", () => {
|
||||
it("it should add bold to the properties", () => {
|
||||
run.bold();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:b");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#italic()", () => {
|
||||
it("it should add italics to the properties", () => {
|
||||
run.italic();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:i");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#underline()", () => {
|
||||
it("it should add underline to the properties", () => {
|
||||
run.underline();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:u");
|
||||
});
|
||||
|
||||
it("should default to 'single' and no color", () => {
|
||||
run.underline();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{"w:rPr": [{"w:u": [{_attr: {"w:val": "single"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should set the style type and color if given", () => {
|
||||
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"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#smallCaps()", () => {
|
||||
it("it should add smallCaps to the properties", () => {
|
||||
run.smallCaps();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:smallCaps");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#caps()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.allCaps();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:caps");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#strike()", () => {
|
||||
it("it should add strike to the properties", () => {
|
||||
run.strike();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:strike");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#doubleStrike()", () => {
|
||||
it("it should add caps to the properties", () => {
|
||||
run.doubleStrike();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[0].root[0].rootKey, "w:dstrike");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#break()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
run.break();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[1].rootKey, "w:br");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#tab()", () => {
|
||||
it("it should add break to the run", () => {
|
||||
run.tab();
|
||||
const newJson = Utility.jsonify(run);
|
||||
assert.equal(newJson.root[1].rootKey, "w:tab");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#font()", () => {
|
||||
it("should allow chaining calls", () => {
|
||||
expect(run.font("Times")).to.equal(run);
|
||||
});
|
||||
|
||||
it("should set the font as named", () => {
|
||||
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"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#color", () => {
|
||||
it("should set the run to the color given", () => {
|
||||
run.color("001122");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{"w:rPr": [{"w:color": [{_attr: {"w:val": "001122"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#size", () => {
|
||||
it("should set the run to the given size", () => {
|
||||
run.size(24);
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{"w:rPr": [{"w:sz": [{_attr: {"w:val": 24}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#style", () => {
|
||||
it("should set the style to the given styleId", () => {
|
||||
run.style("myRunStyle");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{"w:rPr": [{"w:rStyle": [{_attr: {"w:val": "myRunStyle"}}]}]},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
97
src/file/paragraph/run/run.ts
Normal file
97
src/file/paragraph/run/run.ts
Normal file
@ -0,0 +1,97 @@
|
||||
// http://officeopenxml.com/WPtext.php
|
||||
import { Break } from "./break";
|
||||
import { Caps, SmallCaps } from "./caps";
|
||||
import { Bold, Color, DoubleStrike, Italics, Size, Strike } from "./formatting";
|
||||
import { RunProperties } from "./properties";
|
||||
import { RunFonts } from "./run-fonts";
|
||||
import { SubScript, SuperScript } from "./script";
|
||||
import { Style } from "./style";
|
||||
import { Tab } from "./tab";
|
||||
import { Underline } from "./underline";
|
||||
|
||||
import { XmlComponent } from "../../xml-components";
|
||||
|
||||
export class Run extends XmlComponent {
|
||||
private properties: RunProperties;
|
||||
|
||||
constructor() {
|
||||
super("w:r");
|
||||
this.properties = new RunProperties();
|
||||
this.root.push(this.properties);
|
||||
}
|
||||
|
||||
public bold(): Run {
|
||||
this.properties.push(new Bold());
|
||||
return this;
|
||||
}
|
||||
|
||||
public italic(): Run {
|
||||
this.properties.push(new Italics());
|
||||
return this;
|
||||
}
|
||||
|
||||
public underline(underlineType?: string, color?: string): Run {
|
||||
this.properties.push(new Underline(underlineType, color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public color(color: string): Run {
|
||||
this.properties.push(new Color(color));
|
||||
return this;
|
||||
}
|
||||
|
||||
public size(size: number): Run {
|
||||
this.properties.push(new Size(size));
|
||||
return this;
|
||||
}
|
||||
|
||||
public break(): Run {
|
||||
this.root.splice(1, 0, new Break());
|
||||
return this;
|
||||
}
|
||||
|
||||
public tab(): Run {
|
||||
this.root.splice(1, 0, new Tab());
|
||||
return this;
|
||||
}
|
||||
|
||||
public smallCaps(): Run {
|
||||
this.properties.push(new SmallCaps());
|
||||
return this;
|
||||
}
|
||||
|
||||
public allCaps(): Run {
|
||||
this.properties.push(new Caps());
|
||||
return this;
|
||||
}
|
||||
|
||||
public strike(): Run {
|
||||
this.properties.push(new Strike());
|
||||
return this;
|
||||
}
|
||||
|
||||
public doubleStrike(): Run {
|
||||
this.properties.push(new DoubleStrike());
|
||||
return this;
|
||||
}
|
||||
|
||||
public subScript(): Run {
|
||||
this.properties.push(new SubScript());
|
||||
return this;
|
||||
}
|
||||
|
||||
public superScript(): Run {
|
||||
this.properties.push(new SuperScript());
|
||||
return this;
|
||||
}
|
||||
|
||||
public font(fontName: string): Run {
|
||||
this.properties.push(new RunFonts(fontName));
|
||||
return this;
|
||||
}
|
||||
|
||||
public style(styleId: string): Run {
|
||||
this.properties.push(new Style(styleId));
|
||||
return this;
|
||||
}
|
||||
}
|
50
src/file/paragraph/run/script.spec.ts
Normal file
50
src/file/paragraph/run/script.spec.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { Utility } from "../../../tests/utility";
|
||||
import { SubScript, SuperScript } from "./script";
|
||||
|
||||
describe("SubScript", () => {
|
||||
let subScript: SubScript;
|
||||
|
||||
beforeEach(() => {
|
||||
subScript = new SubScript();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Sub Script with correct attributes", () => {
|
||||
const newJson = Utility.jsonify(subScript);
|
||||
const attributes = {
|
||||
val: "subscript",
|
||||
};
|
||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
||||
});
|
||||
|
||||
it("should create a Sub Script with correct root key", () => {
|
||||
const newJson = Utility.jsonify(subScript);
|
||||
assert.equal(newJson.rootKey, "w:vertAlign");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("SuperScript", () => {
|
||||
let superScript: SuperScript;
|
||||
|
||||
beforeEach(() => {
|
||||
superScript = new SuperScript();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Super Script with correct attributes", () => {
|
||||
const newJson = Utility.jsonify(superScript);
|
||||
const attributes = {
|
||||
val: "superscript",
|
||||
};
|
||||
assert.equal(JSON.stringify(newJson.root[0].root), JSON.stringify(attributes));
|
||||
});
|
||||
|
||||
it("should create a Super Script with correct root key", () => {
|
||||
const newJson = Utility.jsonify(superScript);
|
||||
assert.equal(newJson.rootKey, "w:vertAlign");
|
||||
});
|
||||
});
|
||||
});
|
25
src/file/paragraph/run/script.ts
Normal file
25
src/file/paragraph/run/script.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Attributes, XmlComponent } from "../../xml-components";
|
||||
|
||||
export abstract class VerticalAlign extends XmlComponent {
|
||||
|
||||
constructor(type: string) {
|
||||
super("w:vertAlign");
|
||||
this.root.push(new Attributes({
|
||||
val: type,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class SuperScript extends VerticalAlign {
|
||||
|
||||
constructor() {
|
||||
super("superscript");
|
||||
}
|
||||
}
|
||||
|
||||
export class SubScript extends VerticalAlign {
|
||||
|
||||
constructor() {
|
||||
super("subscript");
|
||||
}
|
||||
}
|
34
src/file/paragraph/run/strike.spec.ts
Normal file
34
src/file/paragraph/run/strike.spec.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { Utility } from "../../../tests/utility";
|
||||
import { DoubleStrike, Strike } from "./formatting";
|
||||
|
||||
describe("Strike", () => {
|
||||
let strike: Strike;
|
||||
|
||||
beforeEach(() => {
|
||||
strike = new Strike();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Strike with correct root key", () => {
|
||||
const newJson = Utility.jsonify(strike);
|
||||
assert.equal(newJson.rootKey, "w:strike");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DoubleStrike", () => {
|
||||
let strike: DoubleStrike;
|
||||
|
||||
beforeEach(() => {
|
||||
strike = new DoubleStrike();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Double Strike with correct root key", () => {
|
||||
const newJson = Utility.jsonify(strike);
|
||||
assert.equal(newJson.rootKey, "w:dstrike");
|
||||
});
|
||||
});
|
||||
});
|
13
src/file/paragraph/run/style.ts
Normal file
13
src/file/paragraph/run/style.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "../../xml-components";
|
||||
|
||||
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}));
|
||||
}
|
||||
}
|
19
src/file/paragraph/run/tab.spec.ts
Normal file
19
src/file/paragraph/run/tab.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import { Utility } from "../../../tests/utility";
|
||||
import { Tab } from "./tab";
|
||||
|
||||
describe("Tab", () => {
|
||||
let tab: Tab;
|
||||
|
||||
beforeEach(() => {
|
||||
tab = new Tab();
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Tab with correct root key", () => {
|
||||
const newJson = Utility.jsonify(tab);
|
||||
assert.equal(newJson.rootKey, "w:tab");
|
||||
});
|
||||
});
|
||||
});
|
8
src/file/paragraph/run/tab.ts
Normal file
8
src/file/paragraph/run/tab.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { XmlComponent } from "../../xml-components";
|
||||
|
||||
export class Tab extends XmlComponent {
|
||||
|
||||
constructor() {
|
||||
super("w:tab");
|
||||
}
|
||||
}
|
20
src/file/paragraph/run/text-run.spec.ts
Normal file
20
src/file/paragraph/run/text-run.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { expect } from "chai";
|
||||
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
import { TextRun } from "./text-run";
|
||||
|
||||
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"]},
|
||||
]});
|
||||
});
|
||||
});
|
||||
});
|
10
src/file/paragraph/run/text-run.ts
Normal file
10
src/file/paragraph/run/text-run.ts
Normal file
@ -0,0 +1,10 @@
|
||||
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));
|
||||
}
|
||||
}
|
215
src/file/paragraph/run/underline.spec.ts
Normal file
215
src/file/paragraph/run/underline.spec.ts
Normal file
@ -0,0 +1,215 @@
|
||||
import { assert, expect } from "chai";
|
||||
|
||||
import { Formatter } from "../../../export/formatter";
|
||||
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);
|
||||
assert.equal(newJson.rootKey, "w:u");
|
||||
});
|
||||
|
||||
it("should default to 'single' and no color", () => {
|
||||
const underline = new u.Underline();
|
||||
const tree = new Formatter().format(underline);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:u": [{_attr: {"w:val": "single"}}],
|
||||
});
|
||||
});
|
||||
|
||||
it("should use the given style type and color", () => {
|
||||
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"}}],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should have u:u as the rootKey", () => {
|
||||
const underline = new u.DashDotDotHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.rootKey, "w:u");
|
||||
});
|
||||
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DashDotDotHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dashDotDotHeavy");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DashDotHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dashDotHeavy");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DashLongHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dashLongHeavy");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DashLongUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dashLong");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DashUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dash");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DotDashUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dotDash");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DotDotDashUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dotDotDash");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DottedHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dottedHeavy");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DottedUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "dotted");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.DoubleUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "double");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.SingleUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "single");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.ThickUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "thick");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.WaveUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "wave");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.WavyDoubleUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "wavyDouble");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.WavyHeavyUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "wavyHeavy");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("DashDotDotHeavyUnderline", () => {
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should put value in attribute", () => {
|
||||
const underline = new u.WordsUnderline();
|
||||
const newJson = Utility.jsonify(underline);
|
||||
assert.equal(newJson.root[0].root.val, "words");
|
||||
});
|
||||
});
|
||||
});
|
131
src/file/paragraph/run/underline.ts
Normal file
131
src/file/paragraph/run/underline.ts
Normal file
@ -0,0 +1,131 @@
|
||||
import { Attributes, XmlComponent } from "../../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,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
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