Commit 84b0e39f by Edgar HIPP

Add fix for doc without rId in rels

parent 17fbf596
......@@ -21,3 +21,4 @@ build/
vendor/
js/
test/
coverage/
......@@ -122,7 +122,7 @@
"no-restricted-syntax": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 2,
"no-self-compare": 0,
"no-sequences": 2,
"no-shadow": 0,
"no-shadow-restricted-names": 2,
......
......@@ -35,11 +35,14 @@ module.exports = class ImgManager {
const content = DocUtils.decodeUtf8(file.asText());
this.xmlDoc = DocUtils.str2xml(content);
// Get all Rids
const RidArray = [];
const RidArray = [0];
const iterable = this.xmlDoc.getElementsByTagName("Relationship");
for (let i = 0, tag; i < iterable.length; 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.imageRels = [];
......
"use strict";
const isNaN = function (number) {
return !(number === number);
};
const SubContent = require("docxtemplater").SubContent;
const ImgManager = require("./imgManager");
const ImgReplacer = require("./imgReplacer");
......@@ -131,6 +135,9 @@ class ImageModule {
return null;
}
getImageXml(rId, size) {
if (isNaN(rId)) {
throw new Error("rId is NaN, aborting");
}
return `<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="${size[0]}" cy="${size[1]}"/>
......@@ -182,6 +189,9 @@ class ImageModule {
`;
}
getImageXmlCentered(rId, size) {
if (isNaN(rId)) {
throw new Error("rId is NaN, aborting");
}
return ` <w:p>
<w:pPr>
<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