Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #117 by introducing option #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/inline-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = (html, css, options) => {
'lowerCaseAttributeNames',
'recognizeCDATA',
'recognizeSelfClosing'
]));
]), opts.isDocument);

try {
rules = parseCSS(css);
Expand Down
1 change: 1 addition & 0 deletions test/expected/test-117.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>test-117</div>
1 change: 1 addition & 0 deletions test/fixtures/test-117.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>test-117</div>
9 changes: 9 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
});