“编译” CSS转换为HTML作为内联样式 [英] "Compile" CSS into HTML as inline styles

查看:359
本文介绍了“编译” CSS转换为HTML作为内联样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写电子邮件HTML模板,某些电子邮件客户端不支持< style> 用于指定CSS。应用CSS的唯一替代方法是使用内联样式( style 属性)。是否有工具或库(Node.JS)用于将样式表应用于某些HTML并返回应用了样式的HTML?

I am writing an e-mail HTML template, and some e-mail clients do not support <style> for specifying CSS. The only alternative for applying CSS is to use inline styles (style attribute). Is there a tool or library (Node.JS) for applying a stylesheet to some HTML and getting back the HTML with the styles applied?

该工具不必支持许多选择器; id,类和元素名称选择符应该足以满足我的需要。

The tool does not have to support many selectors; id, class, and element name selectors should be sufficient for my needs.

需要的示例:

// stylesheet.css
a { color: red; }

// email.html
<p>This is a <a href="http://example.com/">test</a></p>

// Expected result
<p>This is a <a href="http://example.com/" style="color: red;">test</a></p>


推荐答案

我认为 suice 是您要查找的内容。

I think juice is what you're looking for.

只需要它,然后将其传递给您的HTML和CSS它为你做这样繁重的工作:

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; }');

它建立在许多成熟的库,包括mootools的光滑,并支持范围广泛的选择器。

It builds on a number of mature libraries including mootools' slick, and supports a broad range of selectors.

您可能还对 node-email-templates 感兴趣, a>,这是节点中动态电子邮件的一个很好的包装器。

You may also be interested in node-email-templates, which is a nice wrapper for dynamic emails in node.

这篇关于“编译” CSS转换为HTML作为内联样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆