diff --git a/lib/markbind/lib/parser.js b/lib/markbind/lib/parser.js index d472722851..fecbd45d81 100644 --- a/lib/markbind/lib/parser.js +++ b/lib/markbind/lib/parser.js @@ -543,8 +543,8 @@ Parser.prototype._rebaseReference = function (node, foundBase) { }); // rebase current element - if (element.attribs[ATTRIB_CWF]) { - const filePath = element.attribs[ATTRIB_CWF]; + if (element.attribs[ATTRIB_INCLUDE_PATH]) { + const filePath = element.attribs[ATTRIB_INCLUDE_PATH]; let newBase = calculateNewBaseUrls(filePath, this.rootPath, this.baseUrlMap); if (newBase) { const { relative, parent } = newBase; @@ -552,10 +552,11 @@ Parser.prototype._rebaseReference = function (node, foundBase) { foundBase[parent] = relative; } - const bases = Object.keys(childrenBase); + const combinedBases = Object.assign({}, childrenBase, foundBase); + const bases = Object.keys(combinedBases); if (bases.length !== 0) { // need to rebase - newBase = childrenBase[bases[0]]; + newBase = combinedBases[bases[0]]; const { children } = element; if (children) { const currentBase = calculateNewBaseUrls(element.attribs[ATTRIB_CWF], this.rootPath, this.baseUrlMap); @@ -563,7 +564,12 @@ Parser.prototype._rebaseReference = function (node, foundBase) { if (currentBase.relative !== newBase) { cheerio.prototype.options.xmlMode = false; const newBaseUrl = `{{hostBaseUrl}}/${newBase}`; - const rendered = nunjucks.renderString(cheerio.html(children), { baseUrl: newBaseUrl }); + const rendered = nunjucks.renderString(cheerio.html(children), { + // This is to prevent the nunjuck call from converting {{hostBaseUrl}} to an empty string + // and let the hostBaseUrl value be injected later. + hostBaseUrl: '{{hostBaseUrl}}', + baseUrl: newBaseUrl, + }); element.children = cheerio.parseHTML(rendered, true); cheerio.prototype.options.xmlMode = true; }