Commit 84b0e39f by Edgar HIPP

Add fix for doc without rId in rels

parent 17fbf596
...@@ -21,3 +21,4 @@ build/ ...@@ -21,3 +21,4 @@ build/
vendor/ vendor/
js/ js/
test/ test/
coverage/
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
"no-restricted-syntax": 2, "no-restricted-syntax": 2,
"no-return-assign": 2, "no-return-assign": 2,
"no-script-url": 2, "no-script-url": 2,
"no-self-compare": 2, "no-self-compare": 0,
"no-sequences": 2, "no-sequences": 2,
"no-shadow": 0, "no-shadow": 0,
"no-shadow-restricted-names": 2, "no-shadow-restricted-names": 2,
......
...@@ -35,11 +35,14 @@ module.exports = class ImgManager { ...@@ -35,11 +35,14 @@ module.exports = class ImgManager {
const content = DocUtils.decodeUtf8(file.asText()); const content = DocUtils.decodeUtf8(file.asText());
this.xmlDoc = DocUtils.str2xml(content); this.xmlDoc = DocUtils.str2xml(content);
// Get all Rids // Get all Rids
const RidArray = []; const RidArray = [0];
const iterable = this.xmlDoc.getElementsByTagName("Relationship"); const iterable = this.xmlDoc.getElementsByTagName("Relationship");
for (let i = 0, tag; i < iterable.length; i++) { for (let i = 0, tag; i < iterable.length; i++) {
tag = iterable[i]; tag = iterable[i];
RidArray.push(parseInt(tag.getAttribute("Id").substr(3), 10)); const id = tag.getAttribute("Id");
if (/^rId[0-9]+$/.test(id)) {
RidArray.push(parseInt(id.substr(3), 10));
}
} }
this.maxRid = DocUtils.maxArray(RidArray); this.maxRid = DocUtils.maxArray(RidArray);
this.imageRels = []; this.imageRels = [];
......
"use strict"; "use strict";
const isNaN = function (number) {
return !(number === number);
};
const SubContent = require("docxtemplater").SubContent; const SubContent = require("docxtemplater").SubContent;
const ImgManager = require("./imgManager"); const ImgManager = require("./imgManager");
const ImgReplacer = require("./imgReplacer"); const ImgReplacer = require("./imgReplacer");
...@@ -131,6 +135,9 @@ class ImageModule { ...@@ -131,6 +135,9 @@ class ImageModule {
return null; return null;
} }
getImageXml(rId, size) { getImageXml(rId, size) {
if (isNaN(rId)) {
throw new Error("rId is NaN, aborting");
}
return `<w:drawing> return `<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="${size[0]}" cy="${size[1]}"/> <wp:extent cx="${size[0]}" cy="${size[1]}"/>
...@@ -182,6 +189,9 @@ class ImageModule { ...@@ -182,6 +189,9 @@ class ImageModule {
`; `;
} }
getImageXmlCentered(rId, size) { getImageXmlCentered(rId, size) {
if (isNaN(rId)) {
throw new Error("rId is NaN, aborting");
}
return ` <w:p> return ` <w:p>
<w:pPr> <w:pPr>
<w:jc w:val="center"/> <w:jc w:val="center"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment