"Compile" CSS into HTML as inline styles
I think juice is what you're looking for.
Simply require it, then pass it your html and css and let it do the heavy lifting for you like this:
var juice = require('juice');
var inlinedcss = juice('<p>Test</p>', 'p { color: red; }');
It builds on a number of mature libraries including mootools' slick, and supports a broad range of selectors.
You may also be interested in node-email-templates, which is a nice wrapper for dynamic emails in node.
Here's the alive javascript projects that does what you want:
juice
. 1.7Mb with dependencies.juice2
. 5.9Mb with dependencies. This is a fork of juice, seems to be containing more options than juice. This one doesn't drop media queries as juice does. Sorts inline css rules alphabetically.styliner
. 4.0Mb with dependencies. This one uses promises instead. Have a couple of different options than juice2. Has acompact
option that other ones don't have that minifies the html. Doesn't read the html file itself as others do. Also extendsmargin
andpadding
shorthands. And in case you somehow modify your native objects(like if you are using sugar) I don't suggest using this till this issue is resolved.
So which one to use? Well it depends on the way you write CSS. They each have different support for edge cases. Better check each and do some tests to understand perfectly.
You could use jsdom + jquery to apply $('a').css({color:'red'});