remove more duplicate classes; add additional values functions; clean up tests

This commit is contained in:
Tom Hunkapiller
2021-05-24 11:28:10 +03:00
parent a56119e7cd
commit ce2a0fb864
38 changed files with 311 additions and 362 deletions

View File

@ -98,18 +98,19 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
return;
}
if (options.bold) {
this.push(new OnOffElement("w:b"));
if (options.bold !== undefined) {
this.push(new OnOffElement("w:b", options.bold));
}
if ((options.boldComplexScript === undefined && options.bold) || options.boldComplexScript) {
this.push(new OnOffElement("w:bCs"));
if ((options.boldComplexScript === undefined && options.bold !== undefined) || options.boldComplexScript) {
this.push(new OnOffElement("w:bCs", options.boldComplexScript ?? options.bold));
}
if (options.italics) {
this.push(new OnOffElement("w:i"));
if (options.italics !== undefined) {
this.push(new OnOffElement("w:i", options.italics));
}
if ((options.italicsComplexScript === undefined && options.italics) || options.italicsComplexScript) {
this.push(new OnOffElement("w:iCs"));
if ((options.italicsComplexScript === undefined && options.italics !== undefined) || options.italicsComplexScript) {
this.push(new OnOffElement("w:iCs", options.italicsComplexScript ?? options.italics));
}
if (options.underline) {
@ -124,7 +125,7 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
this.push(new Color(options.color));
}
if (options.size) {
if (options.size !== undefined) {
this.push(new HpsMeasureElement("w:sz", options.size));
}
const szCs =
@ -133,23 +134,23 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
this.push(new HpsMeasureElement("w:szCs", szCs));
}
if (options.rightToLeft) {
this.push(new OnOffElement("w:rtl"));
if (options.rightToLeft !== undefined) {
this.push(new OnOffElement("w:rtl", options.rightToLeft));
}
// These two are mutually exclusive
if (options.smallCaps) {
this.push(new OnOffElement("w:smallCaps"));
} else if (options.allCaps) {
this.push(new OnOffElement("w:caps"));
if (options.smallCaps !== undefined) {
this.push(new OnOffElement("w:smallCaps", options.smallCaps));
} else if (options.allCaps !== undefined) {
this.push(new OnOffElement("w:caps", options.allCaps));
}
if (options.strike) {
this.push(new OnOffElement("w:strike"));
if (options.strike !== undefined) {
this.push(new OnOffElement("w:strike", options.strike));
}
if (options.doubleStrike) {
this.push(new OnOffElement("w:dstrike"));
if (options.doubleStrike !== undefined) {
this.push(new OnOffElement("w:dstrike", options.doubleStrike));
}
if (options.subScript) {
@ -189,12 +190,12 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent {
this.push(new CharacterSpacing(options.characterSpacing));
}
if (options.emboss) {
this.push(new OnOffElement("w:emboss"));
if (options.emboss !== undefined) {
this.push(new OnOffElement("w:emboss", options.emboss));
}
if (options.imprint) {
this.push(new OnOffElement("w:imprint"));
if (options.imprint !== undefined) {
this.push(new OnOffElement("w:imprint", options.imprint));
}
if (options.shading) {

View File

@ -20,13 +20,9 @@ describe("Run", () => {
"w:r": [
{
"w:rPr": [
{ "w:b": { _attr: { "w:val": true } } },
{ "w:b": {} },
{
"w:bCs": {
_attr: {
"w:val": true,
},
},
"w:bCs": {},
},
],
},
@ -45,13 +41,9 @@ describe("Run", () => {
"w:r": [
{
"w:rPr": [
{ "w:i": { _attr: { "w:val": true } } },
{ "w:i": {} },
{
"w:iCs": {
_attr: {
"w:val": true,
},
},
"w:iCs": {},
},
],
},
@ -116,7 +108,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:smallCaps": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:smallCaps": {} }] }],
});
});
});
@ -128,7 +120,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:caps": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:caps": {} }] }],
});
});
});
@ -140,7 +132,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:strike": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:strike": {} }] }],
});
});
});
@ -152,7 +144,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:dstrike": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:dstrike": {} }] }],
});
});
});
@ -164,7 +156,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:emboss": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:emboss": {} }] }],
});
});
});
@ -176,7 +168,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:imprint": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:imprint": {} }] }],
});
});
});
@ -367,7 +359,7 @@ describe("Run", () => {
});
const tree = new Formatter().format(run);
expect(tree).to.deep.equal({
"w:r": [{ "w:rPr": [{ "w:rtl": { _attr: { "w:val": true } } }] }],
"w:r": [{ "w:rPr": [{ "w:rtl": {} }] }],
});
});
});

View File

@ -59,10 +59,10 @@ describe("SymbolRun", () => {
"w:r": [
{
"w:rPr": [
{ "w:b": { _attr: { "w:val": true } } },
{ "w:bCs": { _attr: { "w:val": true } } },
{ "w:i": { _attr: { "w:val": true } } },
{ "w:iCs": { _attr: { "w:val": true } } },
{ "w:b": {} },
{ "w:bCs": {} },
{ "w:i": {} },
{ "w:iCs": {} },
{ "w:u": { _attr: { "w:val": "double", "w:color": "ff0000" } } },
{ "w:em": { _attr: { "w:val": "dot" } } },
{ "w:color": { _attr: { "w:val": "00FF00" } } },