Optimize XML output by properly constructing objects to send to the xml library so that it can produce proper empty elements.
Rework the way attributes are stored in ImportedXmlComponent to match elsewhere (required allowing for a null xmlKeys in the XmlAttributeComponent interface). Rework the way paragraphs get added to the end of table cells if needed. The goal in both reworks is to not mess around with the objects output from `prepForXml` if we can avoid it. Made the output of RunProperties, ParagraphProperties, TableCellProperties, TableRowProperties, and TableProperties all optional based on whether they contain any attributes or children. Changed code in PageBorders, TableCellMargin, and TableCellBorders that implemented this same thing by overriding `prepForXml` so that it uses the new XmlComponent subclass instead. Removed commented out code that attempted to fix-up XML output and make proper empty elements. Fixed all affected tests. Turn off `no-null-keyword` in the linter as we need to use null to signal to the `xml` library to create an empty element with no attributes (`undefined` will not work in its place). Fixes #306
This commit is contained in:
@ -10,7 +10,7 @@ describe("Spacing", () => {
|
||||
const spacing = new Spacing({ before: 100, after: 120, line: 150 });
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:spacing": [{ _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } }],
|
||||
"w:spacing": { _attr: { "w:after": 120, "w:before": 100, "w:line": 150 } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -18,7 +18,7 @@ describe("Spacing", () => {
|
||||
const spacing = new Spacing({ before: 100 });
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:spacing": [{ _attr: { "w:before": 100 } }],
|
||||
"w:spacing": { _attr: { "w:before": 100 } },
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -30,7 +30,7 @@ describe("ContextualSpacing", () => {
|
||||
const spacing = new ContextualSpacing(true);
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:contextualSpacing": [{ _attr: { "w:val": 1 } }],
|
||||
"w:contextualSpacing": { _attr: { "w:val": 1 } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -38,7 +38,7 @@ describe("ContextualSpacing", () => {
|
||||
const spacing = new ContextualSpacing(false);
|
||||
const tree = new Formatter().format(spacing);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:contextualSpacing": [{ _attr: { "w:val": 0 } }],
|
||||
"w:contextualSpacing": { _attr: { "w:val": 0 } },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -45,14 +45,8 @@ describe("Image", () => {
|
||||
const tree = new Formatter().format(image);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [],
|
||||
},
|
||||
{
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [],
|
||||
},
|
||||
{
|
||||
"w:drawing": [
|
||||
{
|
||||
@ -66,49 +60,41 @@ describe("Image", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:extent": [
|
||||
{
|
||||
_attr: {
|
||||
cx: 20,
|
||||
cy: 20,
|
||||
},
|
||||
"wp:extent": {
|
||||
_attr: {
|
||||
cx: 20,
|
||||
cy: 20,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:effectExtent": [
|
||||
{
|
||||
_attr: {
|
||||
b: 0,
|
||||
l: 0,
|
||||
r: 0,
|
||||
t: 0,
|
||||
},
|
||||
"wp:effectExtent": {
|
||||
_attr: {
|
||||
b: 0,
|
||||
l: 0,
|
||||
r: 0,
|
||||
t: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:docPr": [
|
||||
{
|
||||
_attr: {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
"wp:docPr": {
|
||||
_attr: {
|
||||
descr: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"wp:cNvGraphicFramePr": [
|
||||
{
|
||||
"a:graphicFrameLocks": [
|
||||
{
|
||||
_attr: {
|
||||
noChangeAspect: 1,
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
"a:graphicFrameLocks": {
|
||||
_attr: {
|
||||
noChangeAspect: 1,
|
||||
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -137,27 +123,23 @@ describe("Image", () => {
|
||||
{
|
||||
"pic:nvPicPr": [
|
||||
{
|
||||
"pic:cNvPr": [
|
||||
{
|
||||
_attr: {
|
||||
desc: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
"pic:cNvPr": {
|
||||
_attr: {
|
||||
desc: "",
|
||||
id: 0,
|
||||
name: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"pic:cNvPicPr": [
|
||||
{
|
||||
"a:picLocks": [
|
||||
{
|
||||
_attr: {
|
||||
noChangeArrowheads: 1,
|
||||
noChangeAspect: 1,
|
||||
},
|
||||
"a:picLocks": {
|
||||
_attr: {
|
||||
noChangeArrowheads: 1,
|
||||
noChangeAspect: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -166,22 +148,20 @@ describe("Image", () => {
|
||||
{
|
||||
"pic:blipFill": [
|
||||
{
|
||||
"a:blip": [
|
||||
{
|
||||
_attr: {
|
||||
cstate: "none",
|
||||
"r:embed": "rId{test.png}",
|
||||
},
|
||||
"a:blip": {
|
||||
_attr: {
|
||||
cstate: "none",
|
||||
"r:embed": "rId{test.png}",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:srcRect": [],
|
||||
"a:srcRect": null,
|
||||
},
|
||||
{
|
||||
"a:stretch": [
|
||||
{
|
||||
"a:fillRect": [],
|
||||
"a:fillRect": null,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -197,24 +177,20 @@ describe("Image", () => {
|
||||
{
|
||||
"a:xfrm": [
|
||||
{
|
||||
"a:ext": [
|
||||
{
|
||||
_attr: {
|
||||
cx: 10,
|
||||
cy: 10,
|
||||
},
|
||||
"a:ext": {
|
||||
_attr: {
|
||||
cx: 10,
|
||||
cy: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:off": [
|
||||
{
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
"a:off": {
|
||||
_attr: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -226,7 +202,7 @@ describe("Image", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"a:avLst": [],
|
||||
"a:avLst": null,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -31,7 +31,7 @@ describe("Hyperlink", () => {
|
||||
const tree = new Formatter().format(hyperlink);
|
||||
const runJson = {
|
||||
"w:r": [
|
||||
{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "Hyperlink" } }] }] },
|
||||
{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "Hyperlink" } } }] },
|
||||
{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "https://example.com"] },
|
||||
],
|
||||
};
|
||||
|
@ -40,7 +40,7 @@ describe("Paragraph", () => {
|
||||
expect(tree)
|
||||
.to.be.an("array")
|
||||
.which.includes({
|
||||
"w:r": [{ "w:rPr": [] }, { "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
|
||||
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "this is a test run"] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -52,7 +52,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading1" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading1" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -66,7 +66,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading2" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading2" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -80,7 +80,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading3" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading3" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -94,7 +94,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading4" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading4" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -108,7 +108,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading5" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading5" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -122,7 +122,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Heading6" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Heading6" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -136,7 +136,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "Title" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "Title" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -150,7 +150,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "center" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "center" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -164,7 +164,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "left" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "left" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -178,7 +178,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "right" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "right" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -192,7 +192,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "start" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "start" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -206,7 +206,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "end" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "end" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -220,7 +220,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "distribute" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "distribute" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -234,7 +234,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:jc": [{ _attr: { "w:val": "both" } }] }],
|
||||
"w:pPr": [{ "w:jc": { _attr: { "w:val": "both" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -252,14 +252,12 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 9026,
|
||||
"w:val": "right",
|
||||
},
|
||||
"w:tab": {
|
||||
_attr: {
|
||||
"w:pos": 9026,
|
||||
"w:val": "right",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -281,15 +279,13 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "left",
|
||||
"w:leader": "hyphen",
|
||||
},
|
||||
"w:tab": {
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "left",
|
||||
"w:leader": "hyphen",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -311,15 +307,13 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "right",
|
||||
"w:leader": "dot",
|
||||
},
|
||||
"w:tab": {
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "right",
|
||||
"w:leader": "dot",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -341,15 +335,13 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:tabs": [
|
||||
{
|
||||
"w:tab": [
|
||||
{
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "center",
|
||||
"w:leader": "middleDot",
|
||||
},
|
||||
"w:tab": {
|
||||
_attr: {
|
||||
"w:pos": 100,
|
||||
"w:val": "center",
|
||||
"w:leader": "middleDot",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -367,7 +359,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 1 } }] }],
|
||||
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 1 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -379,7 +371,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:contextualSpacing": [{ _attr: { "w:val": 0 } }] }],
|
||||
"w:pPr": [{ "w:contextualSpacing": { _attr: { "w:val": 0 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -397,16 +389,14 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:pBdr": [
|
||||
{
|
||||
"w:bottom": [
|
||||
{
|
||||
_attr: {
|
||||
"w:val": "single",
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
},
|
||||
"w:bottom": {
|
||||
_attr: {
|
||||
"w:val": "single",
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -430,28 +420,24 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:pBdr": [
|
||||
{
|
||||
"w:left": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:left": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:right": [
|
||||
{
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
"w:val": "single",
|
||||
},
|
||||
"w:right": {
|
||||
_attr: {
|
||||
"w:color": "auto",
|
||||
"w:space": "1",
|
||||
"w:sz": "6",
|
||||
"w:val": "single",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -469,10 +455,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [],
|
||||
},
|
||||
{
|
||||
"w:r": [{ "w:rPr": [] }, { "w:br": [{ _attr: { "w:type": "page" } }] }],
|
||||
"w:r": [{ "w:br": { _attr: { "w:type": "page" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -488,7 +471,7 @@ describe("Paragraph", () => {
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:pageBreakBefore": [],
|
||||
"w:pageBreakBefore": null,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -510,7 +493,7 @@ describe("Paragraph", () => {
|
||||
.which.is.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
||||
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -526,7 +509,7 @@ describe("Paragraph", () => {
|
||||
.which.is.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
||||
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -542,7 +525,7 @@ describe("Paragraph", () => {
|
||||
.which.is.an("array")
|
||||
.which.has.length.at.least(2);
|
||||
expect(tree["w:p"][0]["w:pPr"][1]).to.deep.equal({
|
||||
"w:numPr": [{ "w:ilvl": [{ _attr: { "w:val": 1 } }] }, { "w:numId": [{ _attr: { "w:val": 1 } }] }],
|
||||
"w:numPr": [{ "w:ilvl": { _attr: { "w:val": 1 } } }, { "w:numId": { _attr: { "w:val": 1 } } }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -565,7 +548,7 @@ describe("Paragraph", () => {
|
||||
.which.is.an("array")
|
||||
.which.has.length.at.least(1);
|
||||
expect(tree["w:p"][0]["w:pPr"][0]).to.deep.equal({
|
||||
"w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }],
|
||||
"w:pStyle": { _attr: { "w:val": "ListParagraph" } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -581,11 +564,11 @@ describe("Paragraph", () => {
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [
|
||||
{ "w:pStyle": [{ _attr: { "w:val": "ListParagraph" } }] },
|
||||
{ "w:pStyle": { _attr: { "w:val": "ListParagraph" } } },
|
||||
{
|
||||
"w:numPr": [
|
||||
{ "w:ilvl": [{ _attr: { "w:val": 0 } }] },
|
||||
{ "w:numId": [{ _attr: { "w:val": letterNumbering.id } }] },
|
||||
{ "w:ilvl": { _attr: { "w:val": 0 } } },
|
||||
{ "w:numId": { _attr: { "w:val": letterNumbering.id } } },
|
||||
],
|
||||
},
|
||||
],
|
||||
@ -602,7 +585,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:pStyle": [{ _attr: { "w:val": "myFancyStyle" } }] }],
|
||||
"w:pPr": [{ "w:pStyle": { _attr: { "w:val": "myFancyStyle" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -616,7 +599,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:ind": [{ _attr: { "w:left": 720 } }] }],
|
||||
"w:pPr": [{ "w:ind": { _attr: { "w:left": 720 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -630,7 +613,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:spacing": [{ _attr: { "w:before": 90, "w:line": 50 } }] }],
|
||||
"w:pPr": [{ "w:spacing": { _attr: { "w:before": 90, "w:line": 50 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -642,7 +625,7 @@ describe("Paragraph", () => {
|
||||
paragraph.keepLines();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{ "w:pPr": [{ "w:keepLines": [] }] }],
|
||||
"w:p": [{ "w:pPr": [{ "w:keepLines": null }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -652,7 +635,7 @@ describe("Paragraph", () => {
|
||||
paragraph.keepNext();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{ "w:pPr": [{ "w:keepNext": [] }] }],
|
||||
"w:p": [{ "w:pPr": [{ "w:keepNext": null }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -662,7 +645,7 @@ describe("Paragraph", () => {
|
||||
paragraph.bidirectional();
|
||||
const tree = new Formatter().format(paragraph);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [{ "w:pPr": [{ "w:bidi": [] }] }],
|
||||
"w:p": [{ "w:pPr": [{ "w:bidi": null }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -674,7 +657,7 @@ describe("Paragraph", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:p": [
|
||||
{
|
||||
"w:pPr": [{ "w:outlineLvl": [{ _attr: { "w:val": "0" } }] }],
|
||||
"w:pPr": [{ "w:outlineLvl": { _attr: { "w:val": "0" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
// http://officeopenxml.com/WPparagraphProperties.php
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
|
||||
import { Border } from "./formatting/border";
|
||||
|
||||
export class ParagraphProperties extends XmlComponent {
|
||||
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
public readonly paragraphBorder: Border;
|
||||
|
||||
constructor() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { IgnoreIfEmptyXmlComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
export class RunProperties extends XmlComponent {
|
||||
export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
||||
constructor() {
|
||||
super("w:rPr");
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ describe("Text", () => {
|
||||
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" } }] });
|
||||
expect(f).to.deep.equal({ "w:t": { _attr: { "xml:space": "preserve" } } });
|
||||
});
|
||||
|
||||
it("adds the passed in text to the component", () => {
|
||||
|
@ -9,16 +9,16 @@ describe("RunFonts", () => {
|
||||
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:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }],
|
||||
"w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "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:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } },
|
||||
],
|
||||
"w:rFonts": {
|
||||
_attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -41,7 +41,7 @@ describe("Run", () => {
|
||||
run.underline();
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:u": [{ _attr: { "w:val": "single" } }] }] }],
|
||||
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -49,7 +49,7 @@ describe("Run", () => {
|
||||
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" } }] }] }],
|
||||
"w:r": [{ "w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "990011" } } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -114,7 +114,7 @@ describe("Run", () => {
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] },
|
||||
{ "w:rFonts": { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } } },
|
||||
],
|
||||
},
|
||||
],
|
||||
@ -127,7 +127,7 @@ describe("Run", () => {
|
||||
run.color("001122");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:color": [{ _attr: { "w:val": "001122" } }] }] }],
|
||||
"w:r": [{ "w:rPr": [{ "w:color": { _attr: { "w:val": "001122" } } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -139,7 +139,7 @@ describe("Run", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [{ "w:sz": [{ _attr: { "w:val": 24 } }] }, { "w:szCs": [{ _attr: { "w:val": 24 } }] }],
|
||||
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -151,7 +151,7 @@ describe("Run", () => {
|
||||
run.rightToLeft();
|
||||
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": { _attr: { "w:val": true } } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -162,11 +162,10 @@ describe("Run", () => {
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{ "w:rPr": [] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "begin" } }] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "NUMPAGES"] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "separate" } }] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "end" } }] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -178,11 +177,10 @@ describe("Run", () => {
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{ "w:rPr": [] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "begin" } }] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "PAGE"] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "separate" } }] },
|
||||
{ "w:fldChar": [{ _attr: { "w:fldCharType": "end" } }] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -193,7 +191,7 @@ describe("Run", () => {
|
||||
run.style("myRunStyle");
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [{ "w:rPr": [{ "w:rStyle": [{ _attr: { "w:val": "myRunStyle" } }] }] }],
|
||||
"w:r": [{ "w:rPr": [{ "w:rStyle": { _attr: { "w:val": "myRunStyle" } } }] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -17,17 +17,12 @@ describe("Sequential Identifier", () => {
|
||||
const DEFAULT_SEQ = {
|
||||
"w:r": [
|
||||
{
|
||||
"w:rPr": [],
|
||||
},
|
||||
{
|
||||
"w:fldChar": [
|
||||
{
|
||||
_attr: {
|
||||
"w:fldCharType": "begin",
|
||||
"w:dirty": true,
|
||||
},
|
||||
"w:fldChar": {
|
||||
_attr: {
|
||||
"w:fldCharType": "begin",
|
||||
"w:dirty": true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:instrText": [
|
||||
@ -40,22 +35,18 @@ const DEFAULT_SEQ = {
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:fldChar": [
|
||||
{
|
||||
_attr: {
|
||||
"w:fldCharType": "separate",
|
||||
},
|
||||
"w:fldChar": {
|
||||
_attr: {
|
||||
"w:fldCharType": "separate",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:fldChar": [
|
||||
{
|
||||
_attr: {
|
||||
"w:fldCharType": "end",
|
||||
},
|
||||
"w:fldChar": {
|
||||
_attr: {
|
||||
"w:fldCharType": "end",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ describe("TextRun", () => {
|
||||
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"] }],
|
||||
"w:r": [{ "w:t": [{ _attr: { "xml:space": "preserve" } }, "test"] }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ describe("Underline", () => {
|
||||
const underline = new u.Underline();
|
||||
const tree = new Formatter().format(underline);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:u": [{ _attr: { "w:val": "single" } }],
|
||||
"w:u": { _attr: { "w:val": "single" } },
|
||||
});
|
||||
});
|
||||
|
||||
@ -25,7 +25,7 @@ describe("Underline", () => {
|
||||
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" } }],
|
||||
"w:u": { _attr: { "w:val": "double", "w:color": "FF00CC" } },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user