Inlines css into html source. Added support for Node 4.x and io.js.
npm install juice2-node4
Given HTML, juice will inline your CSS properties into the style
attribute.
``js`
var juice = require('juice2');
juice("/path/to/file.html", function(err, html) {
console.log(html);
});
/path/to/file.html Test:`html`
style.css`css`
p {
text-decoration: underline;
}
Output: Test
`html`
- HTML emails. For a comprehensive list of supported selectors see
here
- Embedding HTML in 3rd-party websites.
* [node-email-templates][1] - Node.js module for rendering beautiful emails with [ejs][2] templates and email-friendly inline CSS using [juice][3].
* [swig-email-templates][4] - Uses [swig][5], which gives you [template inheritance][6], and
can generate a [dummy context][7] from a template.
[1]: https://github.com/niftylettuce/node-email-templates
[2]: https://github.com/visionmedia/ejs
[3]: https://github.com/LearnBoost/juice
[4]: https://github.com/andrewrk/swig-email-templates
[5]: https://github.com/paularmstrong/swig
[6]: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
[7]: https://github.com/andrewrk/swig-dummy-context
* filePath - html fileoptions
* - (optional) object containing these properties:extraCss
- - extra css to apply to the file. Defaults to "".applyStyleTags
- - whether to inline styles in true
Defaults to .applyLinkTags
- [Deprecated, use applyLinksToStyleTags] - whether to resolve tagshead
and inline the resulting styles into document . Defaults to true.applyLinksToStyleTags
- - whether to resolve tagsstyle
and replace them with tags. This works with preserveMediaQueriesapplyLinkTags
unlike the deprecated . Defaults to true.removeStyleTags
- - whether to remove the original true
tags after (possibly) inlining the css from them. Defaults to .preserveMediaQueries
- - preserves all media queries (and contained styles)
within tags as a refinement when removeStyleTags is true.false
Other styles are removed. Defaults to .preserveImportant
- - preserves !important in values. Defaults to false.applyWidthAttributes
- - whether to use any CSS pixel widths to createwidth
attributes on elements set in juice.widthElementsremoveLinkTags
- - whether to remove the original true
tags after (possibly) inlining the css from them. Defaults to .url
- - how to resolve hrefs. Defaults to using filePath. If you wanturl
to override, be sure your has the protocol at the beginning, e.g.http://
or file://.callback(err, html)
* err
- - Error object or null.html
- - contains the html from filePath, with potentially