diff --git a/README.md b/README.md index 50b0738..6dff1d6 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,6 @@ posthtml() ## Options -__encoding__: default `utf-8` +__root__: Root folder path for include. Default `./` + +__encoding__: Default `utf-8` diff --git a/index.js b/index.js index 05bd257..d46846a 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,17 @@ -var toTree = require('posthtml/lib/parser').toTree; +var parser = require('posthtml-parser'); var fs = require('fs'); var path = require('path'); module.exports = function posthtmlInclude(options) { options = options || {}; + options.root = options.root || './'; + options.encoding = options.encoding || 'utf-8'; return function(tree) { tree.match({ tag: 'include' }, function(node) { var src = node.attrs.src || false, content; - if (src) { - content = toTree(fs.readFileSync(path.resolve(src), options.encoding || 'utf-8')); - } + if (src) content = parser(fs.readFileSync(path.resolve(options.root, src), options.encoding)); return { tag: false, content: content diff --git a/package.json b/package.json index 52c96a8..629952d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Include file in HTML", "main": "index.js", "dependencies": { - "posthtml": "^0.3.0" + "posthtml-parser": "^0.1.1" }, "devDependencies": { "chai": "^3.2.0", diff --git a/test/test.js b/test/test.js index d7bc921..b8545e7 100644 --- a/test/test.js +++ b/test/test.js @@ -3,9 +3,6 @@ var plugin = require('..'); var posthtml = require('posthtml'); var expect = require('chai').expect; -var HTMLINCLUDE = '