Skip to content

Commit

Permalink
fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Mar 2, 2023
1 parent e1d4df4 commit 6596018
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -51,9 +51,16 @@ function parseLocals({options, node}, optionLocals, attributeLocals) {
* @param {String} href [node's href attribute value]
* @return {Promise<String>} [Promise with file content's]
*/
function readFile(options, href) {
function readFile(options, href, tree) {
const filePath = path.join(path.isAbsolute(href) ? options.root : path.dirname(options.from), href);

if (tree.messages) {
tree.messages.push({
type: 'dependency',
file: filePath
});
}

return new Promise((resolve, reject) => {
fs.readFile(filePath, 'utf8', (error, response) => error ? reject(error) : resolve(response));
});
Expand All @@ -69,7 +76,7 @@ function parse(options) {

tree.match(match(`${options.tag}[${options.attribute}]`), node => {
promises.push(
() => readFile(options, node.attrs[options.attribute])
() => readFile(options, node.attrs[options.attribute], tree)
.then(processNodeContentWithPosthtml(node, options))
.then(tree => { // Recursively call parse with node's content tree
return parse(Object.assign({}, options, {
Expand Down

0 comments on commit 6596018

Please sign in to comment.