mjml README

The project's README from github.com/mjmlio/mjml. As one markdown file: README.md.

Developed by


github actions

| Introduction | Installation | Usage |


Introduction

MJML is a markup language created by Mailjet and designed to reduce the pain of coding a responsive email. Its semantic syntax makes the language easy and straightforward while its rich standard components library shortens your development time and lightens your email codebase. MJML’s open-source engine takes care of translating the MJML you wrote into responsive HTML.

Installation

You can install MJML with NPM to use it with NodeJS or the Command Line Interface. If you're not sure what those are, head over to Usage for other ways to use MJML.

npm install mjml

Development

To work on MJML, make changes and create pull requests, download and install yarn for easy development.

git clone https://github.com/mjmlio/mjml.git && cd mjml
yarn
yarn build

You can also run yarn build:watch to rebuild the package as you code.

Usage

Online

Don't want to install anything? Use the free online editor!

try it live

Applications and plugins

MJML comes with tools and plugins, check out:

For more tools, check the Community page.

Command line interface

Compiles the file and outputs the HTML generated in output.html

mjml input.mjml -o output.html

You can pass optional arguments to the CLI and combine them.

argument description default value
mjml [input] -o [output] Writes the output to [output]
mjml [input] -s Writes the output to stdout
mjml [input] -s --noStdoutFileComment Writes the output to stdout without file comment in the first line
mjml -w [input] Watches the changes made to [input] (file or folder)
mjml [input] --config.allowIncludes Enables mj-include processing (true or false) false
mjml [input] --config.allowMixedSyntax Allows mixing block and CSS variable syntax when sanitizeStyles is enabled (true or false) false
mjml [input] --config.beautify Beautifies the output (true or false) true
mjml [input] --config.includePath Adds allowlisted include root(s), as a string path or JSON array of paths
mjml [input] --config.minify Minifies the output (true or false) false
mjml [input] --config.minifyOptions Options for HTML minifier, use minifyCss to control CSS minification See mjml-cli documentation
mjml [input] --config.juicePreserveTags Preserve some tags when inlining CSS See mjml-cli documentation
mjml [input] --config.mjmlConfigPath Path to .mjmlconfig file for custom components current working directory
mjml [input] --config.sanitizeStyles Sanitizes template variables inside CSS before minification (true or false) false
mjml [input] --config.useMjmlConfigOptions Allows to use the options attribute from .mjmlconfig file false
mjml [input] --config.templateSyntax Sets custom template delimiters as JSON array ([{"prefix":"{{","suffix":"}}"}]) [{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}]

See mjml-cli documentation for more information about config options.

Inside Node.js

import mjml2html from 'mjml'

/*
  Compile an mjml string
*/
async function renderMjml() {
  const htmlOutput = await mjml2html(`
    <mjml>
      <mj-body>
        <mj-section>
          <mj-column>
            <mj-text>
              Hello World!
            </mj-text>
          </mj-column>
        </mj-section>
      </mj-body>
    </mjml>
  `, options)

  /*
    Print the responsive HTML generated and MJML errors if any
  */
  console.log(htmlOutput)
}

renderMjml()

You can pass optional options as an object to the mjml2html function:

option unit description default value
allowMixedSyntax boolean Allows mixed block/value/property template syntaxes during CSS sanitization false
beautify boolean Option to beautify the HTML output false
filePath string Path of file, used for relative paths in mj-include instances .
fonts object Default fonts imported in the HTML rendered by MJML See in index.js
ignoreIncludes boolean Option to ignore mj-include instances true
includePath string or string[] Additional allowlisted include root(s), used when ignoreIncludes is false
juicePreserveTags object Preserve some tags when inlining CSS, see documentation for more info
keepComments boolean Option to keep comments in the HTML output true
minify boolean Option to minify the HTML output false
minifyOptions object Options for htmlnano minification (including minifyCss), see documentation for more info
mjmlConfigPath string The path or directory of the .mjmlconfig file (for custom components use) process.cwd()
preprocessors array of functions Preprocessors applied to the xml before parsing. Input must be xml, not json. Functions must be (xml: string) => string []
sanitizeStyles boolean Sanitizes template variables in CSS before minification false
templateSyntax array of objects Custom template delimiters used by sanitization ([{ prefix, suffix }]) [{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}]
useMjmlConfigOptions boolean Allows to use the options attribute from .mjmlconfig file false
validationLevel string Available values for the validator: strict, soft, skip soft.

Client-side (in browser)

var mjml2html = require('mjml-browser')

/*
  Compile a mjml string
*/
mjml2html(`
  <mjml>
    <mj-body>
      <mj-section>
        <mj-column>
          <mj-text>
            Hello World!
          </mj-text>
        </mj-column>
      </mj-section>
    </mj-body>
  </mjml>
`, options).then(function (htmlOutput) {
  /*
    Print the responsive HTML generated and MJML errors if any
  */
  console.log(htmlOutput)
})

API

A free-to-use MJML API is available to make it easy to integrate MJML in your application. Head over here to learn more about the API.

MJML Slack

MJML wouldn't be as cool without its amazing community. Head over the Community Slack to meet fellow MJML'ers.

mjml (mjmlio/mjml)

Searching Database…

18.3K ·GitHub
MJML 是什么?MJML 是由 Mailjet 创建的标记语言,让你用简单的语义标签编写自适应的 HTML 邮件,不必手写基于表格的 HTML 和内联 CSS。
它是框架、库还是命令行工具?三者都是:它是一种带开源编译引擎的标记语言,可以作为 Node.js 库使用,也可以通过命令行界面调用,或者通过在线工具和编辑器工具使用。
我该怎么开始使用?如果用于 Node.js 或命令行,可以通过 NPM 安装;也可以不安装任何东西,直接使用免费的在线编辑器。
编写 MJML 模板前需要准备什么?只需要 Node.js 和 NPM 来安装这个包;如果要为 MJML 本身贡献代码,还需要 Yarn。
处理引入文件或样式清理时,命令行需要额外的参数吗?需要。有几项功能默认是关闭的:mj-include 处理、混合模板语法和样式清理,都需要显式加上参数,例如 --config.allowIncludes 或 --config.sanitizeStyles。
我到底怎么在文件上运行编译器?使用 mjml 命令,例如 'mjml [input] -o [output]' 可以把 HTML 写入文件;使用 '-s' 则会将其输出到标准输出(stdout)。
不在本地安装任何东西,能使用 MJML 吗?可以。有免费的在线编辑器,也有可免费使用的 MJML API,可以在不做本地配置的情况下,把 MJML 编译功能集成到你自己的应用中。
有写 MJML 的编辑器插件吗?有。官方提供 Visual Studio Code 扩展(可以内置安装,也可以从 Marketplace 或 Open VSX 获取),还有 Sublime Text 插件。
能自定义输出的 HTML,比如压缩或美化吗?可以。命令行和 Node API 都支持 minify、beautify 和 minifyOptions 等选项,用来控制生成的 HTML 的格式和大小。
Creator
mjmlio
Size
12.7 MB
Stars
18.3K
Age
10y
Commits · 90 Days