将css转换为行内样式的方案css-inline
文章目录

聊聊场景
- 发送邮件
- 在第三方网站中嵌入HTML
- 从其他编辑器拷贝编辑好的文章发布到微信、今日头条等自媒体
在以上场景使用行内样式的兼容性要高很多,也可以保持原样式不变
解决方案
这两种方案功能和 Api 非常相似,这里就以 juice 为例
安装
npm i juice --save
使用
import juice from 'juice'
const html = `
<div class="test"><h1>测试Juice</h1></div>
<style>
div{
width: 90%;
height: 500px;
}
</style>
`
const result = juice(html)
console.log(result)
结果
<div style="width: 90%; height: 500px;"><h1>测试Juice</h1></div>
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论