@jsreport/jsreport-docx
Advanced tools
Comparing version 4.3.0 to 4.4.0
@@ -308,2 +308,16 @@ const path = require('path') | ||
if (currentDocxMeta.backgroundColor != null) { | ||
const backgroundColor = currentDocxMeta.backgroundColor.slice(1) | ||
cellPrChildren.push( | ||
createNode(doc, 'w:shd', { | ||
attributes: { | ||
'w:val': 'clear', | ||
'w:color': 'auto', | ||
'w:fill': backgroundColor | ||
} | ||
}) | ||
) | ||
} | ||
if (currentDocxMeta.colspan != null) { | ||
@@ -310,0 +324,0 @@ cellPrChildren.push( |
@@ -391,4 +391,7 @@ const cheerio = require('cheerio') | ||
// properties here will be removed once applied to table item, | ||
// so children does not inherit them, if some exception needs to be made | ||
// then be aware and add logic for it here | ||
const allNotNullPropertiesMap = { | ||
cell: ['indent', 'spacing'] | ||
cell: ['backgroundColor', 'indent', 'spacing'] | ||
} | ||
@@ -409,4 +412,2 @@ | ||
props[prop] = data[prop] | ||
// indent and spacing should be removed once applied to table item, | ||
// so children does not inherit them | ||
delete data[prop] | ||
@@ -413,0 +414,0 @@ } |
@@ -394,4 +394,9 @@ const { getDimension, pxToEMU, cmToEMU, emuToTOAP } = require('../../utils') | ||
// we normalize here and add default paragraph and empty text for empty cell | ||
if (newCell.children.length === 0) { | ||
// we normalize the following cases to prevent producing broken document: | ||
// - cell can not be empty | ||
// - if cell contain nested table and it is last child then we need to add an empty paragraph after it | ||
if ( | ||
newCell.children.length === 0 || | ||
newCell.children[newCell.children.length - 1].type === 'table' | ||
) { | ||
newCell.children.push({ | ||
@@ -415,2 +420,6 @@ type: 'paragraph', | ||
if (cell.backgroundColor != null) { | ||
newCell.backgroundColor = cell.backgroundColor | ||
} | ||
if (cell.indent != null) { | ||
@@ -417,0 +426,0 @@ newCell.indent = cell.indent |
@@ -1,2 +0,2 @@ | ||
const { nodeListToArray, getPictureElInfo } = require('../utils') | ||
const { nodeListToArray, getPictureElInfo, decodeURIComponentRecursive } = require('../utils') | ||
@@ -89,3 +89,3 @@ module.exports = (files, headerFooterRefs) => { | ||
const decodedTarget = decodeURIComponent(hyperlinkRelEl.getAttribute('Target')) | ||
const decodedTarget = decodeURIComponentRecursive(hyperlinkRelEl.getAttribute('Target')) | ||
// we ensure to create a bookmark always: | ||
@@ -92,0 +92,0 @@ // - even if the image is not linked to a bookmark (linked to a url) |
const path = require('path') | ||
const { nodeListToArray } = require('../utils') | ||
const { nodeListToArray, decodeURIComponentRecursive } = require('../utils') | ||
@@ -78,3 +78,3 @@ // the endnotes/footnotes/hyperlinks are defined at two places, in the endnotes|footnotes.xml | ||
// word stores link's value encoded | ||
const decodedTarget = decodeURIComponent(clonedRelationshipEl.getAttribute('Target')) | ||
const decodedTarget = decodeURIComponentRecursive(clonedRelationshipEl.getAttribute('Target')) | ||
@@ -81,0 +81,0 @@ if (decodedTarget.includes('{{')) { |
@@ -1,2 +0,2 @@ | ||
const { nodeListToArray, getPictureElInfo } = require('../utils') | ||
const { nodeListToArray, getPictureElInfo, decodeURIComponentRecursive } = require('../utils') | ||
@@ -96,3 +96,3 @@ module.exports = function processImage (files, doc, drawingEl, relsDoc) { | ||
const decodedTarget = decodeURIComponent(hyperlinkRelElClone.getAttribute('Target')) | ||
const decodedTarget = decodeURIComponentRecursive(hyperlinkRelElClone.getAttribute('Target')) | ||
@@ -99,0 +99,0 @@ hyperlinkRelElClone.setAttribute('originalTarget', decodedTarget) |
@@ -524,2 +524,27 @@ const path = require('path') | ||
/** | ||
* decodes a URI from a value that was encoded multiple times | ||
* | ||
* MS programs (PowerPoint, etc) in some cases can encode a string multiple times, | ||
* the final value stored in xml can be a string that was encoded multiple times. | ||
* for example `{{linkURL}}` string is encoded as `%25252525257B%25252525257BlinkURL%25252525257D%25252525257D` which indicates | ||
* that the value was encoded multiple times, so as a workaround in this function we decode | ||
* recursively until the decode no longer returns different string | ||
*/ | ||
function decodeURIComponentRecursive (str) { | ||
let decoded = decodeURIComponent(str) | ||
// return fast if the string is not encoded | ||
if (decoded === str) { | ||
return str | ||
} | ||
while (decoded !== str) { | ||
str = decoded | ||
decoded = decodeURIComponent(str) | ||
} | ||
return decoded | ||
} | ||
module.exports.normalizeSingleTextElInRun = (textEl, doc) => { | ||
@@ -705,1 +730,2 @@ const rEl = getClosestEl(textEl, 'w:r') | ||
module.exports.nodeListToArray = nodeListToArray | ||
module.exports.decodeURIComponentRecursive = decodeURIComponentRecursive |
{ | ||
"name": "@jsreport/jsreport-docx", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "jsreport recipe rendering docx files", | ||
@@ -54,3 +54,3 @@ "keywords": [ | ||
"@jsreport/jsreport-assets": "4.1.1", | ||
"@jsreport/jsreport-core": "4.3.1", | ||
"@jsreport/jsreport-core": "4.4.0", | ||
"@jsreport/jsreport-handlebars": "4.0.1", | ||
@@ -57,0 +57,0 @@ "@jsreport/studio-dev": "4.0.0", |
@@ -10,2 +10,8 @@ # @jsreport/jsreport-docx | ||
### 4.4.0 | ||
- docx, pptx: use decodeURIComponentRecursive helper to handle better different cases of MS Programs storing target urls encoded multiple times | ||
- docxHtml: add support for generating nested tables | ||
- docxHtml: support for table, row, cell background color and color styles | ||
### 4.3.0 | ||
@@ -12,0 +18,0 @@ |
398254
9273
116