added different types of underline

This commit is contained in:
Dolan Miu
2016-07-13 00:59:53 +01:00
parent 54b2c16d7a
commit adb4e933ef
5 changed files with 172 additions and 13 deletions

View File

@ -20,17 +20,6 @@ export class Italics extends XmlComponent {
}
}
// TODO needs work. add more types of underline
export class Underline extends XmlComponent {
constructor() {
super("w:u");
this.root.push(new Attributes({
val: true
}));
}
}
export class Caps extends XmlComponent {
constructor() {

View File

@ -1,11 +1,12 @@
import {XmlComponent, Attributes} from "../xml-components";
import {RunProperties} from "./properties";
import {Bold, Italics, Underline} from "./formatting";
import {Bold, Italics} from "./formatting";
import {Tab} from "./tab";
import {Break} from "./break";
import {SmallCaps, Caps} from "./caps";
import {Strike, DoubleStrike} from "./strike";
import {SubScript, SuperScript} from "./script";
import {Underline} from "./underline"
export class Run extends XmlComponent {
private properties: RunProperties;

132
ts/docx/run/underline.ts Normal file
View File

@ -0,0 +1,132 @@
import {XmlComponent, Attributes} from "../xml-components";
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() {
super("");
}
}
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

@ -10,7 +10,7 @@ function jsonify(obj: Object) {
return JSON.parse(stringifiedJson);
}
describe.only("Run", () => {
describe("Run", () => {
let run: Run;
beforeEach(() => {

View File

@ -0,0 +1,37 @@
import * as u from "../../../docx/run/underline";
import {TextRun} from "../../../docx/run/text-run";
import {assert} from "chai";
function jsonify(obj: Object) {
let stringifiedJson = JSON.stringify(obj);
return JSON.parse(stringifiedJson);
}
describe.only("Underline", () => {
describe("#constructor()", () => {
it("should create a new Underline object", () => {
let underline = new u.Underline();
let newJson = jsonify(underline);
assert.equal(newJson.rootKey, "w:u");
});
});
});
describe.only("Underline", () => {
describe("#constructor()", () => {
it("should create a new Underline object", () => {
let underline = new u.DashDotDotHeavyUnderline();
let newJson = jsonify(underline);
assert.equal(newJson.rootKey, "w:u");
});
it("should put value in attribute", () => {
let underline = new u.DashDotDotHeavyUnderline();
let newJson = jsonify(underline);
assert.equal(newJson.rootKey, "w:u");
});
});
});