andrewrk / juice

Juice inlines CSS stylesheets into your HTML source.
MIT License
60 stars 13 forks source link

Build Status

Juice

Given HTML, juice will inline your CSS properties into the style attribute.

How to use

var juice = require('juice2');
juice("/path/to/file.html", function(err, html) {
  console.log(html);
});

/path/to/file.html:

<html>
<head>
  <style>
    p { color: red; }
  </style>
  <link rel="stylesheet" href="https://github.com/andrewrk/juice/blob/master/style.css">
</head>
<body>
  <p>Test</p>
</body>
</html>

style.css

p {
  text-decoration: underline;
}

Output:

<html>
<head>
</head>
<body>
  <p style="color: red; text-decoration: underline;">Test</p>
</body>
</html>

What is this useful for ?

Projects using juice

Documentation

juice(filePath, [options], callback)

juice.juiceContent(html, options, callback)

juice.juiceDocument(document, options, callback)

Operates on a jsdom instance. Be sure to use the same jsdom version that juice uses. Also be sure to clean up after you are done. You may have to call document.parentWindow.close() to free up memory.

juice.inlineContent(html, css)

This takes html and css and returns new html with the provided css inlined. It does not look at <style> or <link rel="stylesheet"> elements at all.

juice.inlineDocument(document, css, options)

Given a jsdom instance and css, this modifies the jsdom instance so that the provided css is inlined. It does not look at <style> or <link rel="stylesheet"> elements at all.

juice.ignoredPseudos

Array of ignored pseudo-selectors such as 'hover' and 'active'.

juice.widthElements

Array of HTML elements that can receive width attributes.

3rd-party