diff --git a/README.md b/README.md index 756353c..d7e65a6 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,13 @@ Default: `{ EJS: { start: '<%', end: '%>' }, HBS: { start: '{{', end: '}}' } }` An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing and inlining. For example, Handlebars (hbs) templates are `HBS: {start: '{{', end: '}}'}`. `codeBlocks` can fix problems where otherwise inline-css might interpret code like `<=` as HTML, when it is meant to be template language code. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `codeBlocks: {...}` do `codeBlocks.myBlock = {...}`. +#### options.isDocument + +Type: `Boolean` +Default: `true` + +Whether to wrap given html fragment with html, head, and body elements if necessary. It is directly passed to [cheerio.load](https://github.com/cheeriojs/cheerio#loading). + ### Special markup #### data-embed diff --git a/index.js b/index.js index 9bad1a8..2bf153e 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,8 @@ module.exports = (html, options) => new Promise((resolve, reject) => { lowerCaseTags: true, lowerCaseAttributeNames: false, recognizeCDATA: false, - recognizeSelfClosing: false + recognizeSelfClosing: false, + isDocument: true }, options); inlineContent(String(html), opt) diff --git a/lib/inline-css.js b/lib/inline-css.js index eabf1e7..26ff1b3 100644 --- a/lib/inline-css.js +++ b/lib/inline-css.js @@ -57,7 +57,7 @@ module.exports = (html, css, options) => { 'lowerCaseAttributeNames', 'recognizeCDATA', 'recognizeSelfClosing' - ])); + ]), opts.isDocument); try { rules = parseCSS(css); diff --git a/test/expected/test-117.html b/test/expected/test-117.html new file mode 100644 index 0000000..a7a7ce5 --- /dev/null +++ b/test/expected/test-117.html @@ -0,0 +1 @@ +
test-117
\ No newline at end of file diff --git a/test/fixtures/test-117.html b/test/fixtures/test-117.html new file mode 100644 index 0000000..a7a7ce5 --- /dev/null +++ b/test/fixtures/test-117.html @@ -0,0 +1 @@ +
test-117
\ No newline at end of file diff --git a/test/main.js b/test/main.js index 0475abb..ce3b3f3 100644 --- a/test/main.js +++ b/test/main.js @@ -298,4 +298,13 @@ describe('inline-css', () => { }; compare(path.join('test', 'fixtures', 'codeblocks-external.html'), path.join('test', 'expected', 'codeblocks-external.html'), options, done); }); + + it('Should insert html root elements if isDocument not set', done => { + const options = { + url: './', + isDocument: false + }; + + compare(path.join('test', 'fixtures', 'test-117.html'), path.join('test', 'expected', 'test-117.html'), options, done); + }) });