mrml mjml 的rust 实现

mrml 是mjml 的rust 实现,同时还提供了webassembly 的支持,当然比较强大的是mrml 同时也实现了python binding

webassembly 使用

  • 代码
const { Engine } = require("mrml");
const engine = new Engine();
const result = engine.toHtml("<mjml><mj-body>Hello World</mj-body></mjml>");
console.log(result)
  • 效果
{
  type: 'success',
  content: '<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head><title></title><!--[if !mso]><!--><meta http-equiv="X-UA-Compatible" content="IE=edge"><!--<![endif]--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1">\n' +
    '<style type="text/css">\n' +
    '#outlook a { padding: 0; }\n' +
    'body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }\n' +
    'table, td { border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }\n' +
    'img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }\n' +
    'p { display: block; margin: 13px 0; }\n' +
    '</style>\n' +
    '<!--[if mso]>\n' +
    '<noscript>\n' +
    '<xml>\n' +
    '<o:OfficeDocumentSettings>\n' +
    '  <o:AllowPNG/>\n' +
    '  <o:PixelsPerInch>96</o:PixelsPerInch>\n' +
    '</o:OfficeDocumentSettings>\n' +
    '</xml>\n' +
    '</noscript>\n' +
    '<![endif]-->\n' +
    '<!--[if lte mso 11]>\n' +
    '<style type="text/css">\n' +
    '.mj-outlook-group-fix { width:100% !important; }\n' +
    '</style>\n' +
    '<![endif]-->\n' +
    '</head><body style="word-spacing:normal;"><div>Hello World</div></body></html>'
}

说明

mrml 提供的python binding 也是比较方便的,很值得试用

参考资料

https://github.com/jdrouet/mrml
https://documentation.mjml.io/
https://github.com/mjmlio/mjml

posted on 2023-12-28 11:39  荣锋亮  阅读(6)  评论(0编辑  收藏  举报

导航