Merge branch 'master' of github.com:dolanmiu/docx into feat/declaritive

# Conflicts:
#	src/file/paragraph/run/run.ts
This commit is contained in:
Dolan
2019-08-06 21:06:06 +01:00
14 changed files with 380 additions and 54 deletions

View File

@ -113,7 +113,7 @@ export class Imprint extends XmlComponent {
}
}
export class Shadow extends XmlComponent {
/* export class Shadow extends XmlComponent {
constructor() {
super("w:shadow");
this.root.push(
@ -122,7 +122,7 @@ export class Shadow extends XmlComponent {
}),
);
}
}
} */
export class SmallCaps extends XmlComponent {
constructor() {
@ -178,3 +178,51 @@ export class RightToLeft extends XmlComponent {
);
}
}
export class Highlight extends XmlComponent {
constructor(color: string) {
super("w:highlight");
this.root.push(
new Attributes({
val: color,
}),
);
}
}
export class HighlightComplexScript extends XmlComponent {
constructor(color: string) {
super("w:highlightCs");
this.root.push(
new Attributes({
val: color,
}),
);
}
}
export class Shadow extends XmlComponent {
constructor(value: string, fill: string, color: string) {
super("w:shd");
this.root.push(
new Attributes({
val: value,
fill: fill,
color: color,
}),
);
}
}
export class ShadowComplexScript extends XmlComponent {
constructor(value: string, fill: string, color: string) {
super("w:shdCs");
this.root.push(
new Attributes({
val: value,
fill: fill,
color: color,
}),
);
}
}

View File

@ -129,6 +129,54 @@ describe("Run", () => {
});
});
describe("#highlight()", () => {
it("it should add highlight to the properties", () => {
run.highlight("005599");
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
{
"w:rPr": [
{ "w:highlight": { _attr: { "w:val": "005599" } } },
{
"w:highlightCs": {
_attr: {
"w:val": "005599",
},
},
},
],
},
],
});
});
});
describe("#shadow()", () => {
it("it should add shadow to the properties", () => {
run.shadow("pct10", "00FFFF", "FF0000");
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [
{
"w:rPr": [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{
"w:shdCs": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
},
},
],
},
],
});
});
});
describe("#break()", () => {
it("it should add break to the run", () => {
const run = new Run({});

View File

@ -7,9 +7,13 @@ import {
BoldComplexScript,
Color,
DoubleStrike,
Highlight,
HighlightComplexScript,
Italics,
ItalicsComplexScript,
RightToLeft,
Shadow,
ShadowComplexScript,
Size,
SizeComplexScript,
Strike,
@ -140,4 +144,56 @@ export class Run extends XmlComponent {
this.root.push(new End());
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, hint?: string | undefined): Run {
this.properties.push(new RunFonts(fontName, hint));
return this;
}
public style(styleId: string): Run {
this.properties.push(new Style(styleId));
return this;
}
public highlight(color: string): Run {
this.properties.push(new Highlight(color));
this.properties.push(new HighlightComplexScript(color));
return this;
}
public shadow(value: string, fill: string, color: string): Run {
this.properties.push(new Shadow(value, fill, color));
this.properties.push(new ShadowComplexScript(value, fill, color));
return this;
}
}