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

@ -307,5 +307,51 @@ describe("CharacterStyle", () => {
],
});
});
it("#highlight", () => {
const style = new CharacterStyle("myStyleId").highlight("005599");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": "99",
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});
it("#shadow", () => {
const style = new CharacterStyle("myStyleId").shadow("pct10", "00FFFF", "FF0000");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
"w:uiPriority": {
_attr: {
"w:val": "99",
},
},
},
{
"w:unhideWhenUsed": EMPTY_OBJECT,
},
],
});
});
});
});

View File

@ -58,4 +58,12 @@ export class CharacterStyle extends Style {
this.root.push(new SemiHidden());
return this;
}
public highlight(color: string): CharacterStyle {
return this.addRunProperty(new formatting.Highlight(color));
}
public shadow(value: string, fill: string, color: string): CharacterStyle {
return this.addRunProperty(new formatting.Shadow(value, fill, color));
}
}

View File

@ -375,6 +375,32 @@ describe("ParagraphStyle", () => {
});
});
it("#highlight", () => {
const style = new ParagraphStyle("myStyleId").highlight("005599");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
],
});
});
it("#shadow", () => {
const style = new ParagraphStyle("myStyleId").shadow("pct10", "00FFFF", "FF0000");
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
],
});
});
describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => {
const style = new ParagraphStyle("myStyleId").underline();

View File

@ -114,6 +114,14 @@ export class ParagraphStyle extends Style {
return this.addRunProperty(new formatting.CharacterSpacing(value));
}
public highlight(color: string): ParagraphStyle {
return this.addRunProperty(new formatting.Highlight(color));
}
public shadow(value: string, fill: string, color: string): ParagraphStyle {
return this.addRunProperty(new formatting.Shadow(value, fill, color));
}
// --------------------- Paragraph formatting ------------------------ //
public center(): ParagraphStyle {