4.15.3 • Published 2 months ago

mjml-validator v4.15.3

Weekly downloads
229,933
License
MIT
Repository
github
Last release
2 months ago

Validating MJML

MJML provides a validation layer that helps you building your email. It can detect if you misplaced or mispelled a MJML component, or if you used any unauthorised attribute on a specific component. It supports 3 levels of validation:

  • skip: your document is rendered without going through validation
  • soft: your document is going through validation and is rendered, even if it has errors
  • strict: your document is going through validation and is not rendered if it has any error

By default, the level is set to soft.

In CLI

When using the mjml command line, you can add the option -l or --level with the validation level you want.

Validates the file without rendering it

mjml --validate template.mjml

Sets the validation level to skip (so that the file is not validated) and renders the file

mjml -l skip -r template.mjml

In Javascript

In Javascript, you can provide the level through the options parameters on MJMLRenderer. Ex: new MJMLRenderer(inputMJML, { level: strict })

strict will raise a MJMLValidationError exception. This object has 2 methods:

  • getErrors returns an array of objects with line, message, tagName as well as a formattedMessage which contains the line, message and tagName concatenated in a sentence.
  • getMessages returns an array of formattedMessage.

When using soft, no exception will be raised. You can get the errors using the object returned by the render method errors. It is the same object returned by getErrors on strict mode.

Use of .mjmlconfig file

If not exists, add a .mjmlconfig file at the root of your project (where you execute the mjml command). Add the following key to the json:

{
    ...
    "validators": [
        "validateTag",
        "validateAttribute",
        "validChildren",
        "./validators/ColumnCount.js",
    ]
}

"validateTag", "validateAttribute" and "validChildren" are the default validation rules. If you want to add custom rules, you can add the path to the file where the validtion function resides.

5.0.0-alpha.1

2 months ago

5.0.0-alpha.0

2 months ago

4.15.3

2 months ago

4.15.1

3 months ago

4.15.2

3 months ago

4.13.0

2 years ago

4.12.0

2 years ago

4.11.0

2 years ago

4.10.4

3 years ago

4.10.3

3 years ago

4.10.2

3 years ago

4.10.1

3 years ago

4.10.0

3 years ago

4.9.3

3 years ago

4.9.2

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.1

4 years ago

4.7.0-beta.2

4 years ago

4.7.0-beta.1

4 years ago

4.7.0-beta.0

4 years ago

4.6.3

4 years ago

4.6.2

4 years ago

4.6.3-alpha.0

4 years ago

4.5.0

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.4.0-beta.3

5 years ago

4.4.0-beta.2

5 years ago

4.4.0-beta.1

5 years ago

4.3.0

5 years ago

4.2.1

5 years ago

4.2.0

6 years ago

4.2.0-beta.3

6 years ago

4.2.0-beta.2

6 years ago

4.2.0-beta.1

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.1.0-beta.4

6 years ago

4.1.0-beta.3

6 years ago

4.1.0-beta.2

6 years ago

4.1.0-beta.1

6 years ago

4.0.5

6 years ago

4.0.4

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

4.0.0-beta.2

6 years ago

4.0.0-beta.1

6 years ago

4.0.0-alpha.4

6 years ago

3.3.5

7 years ago

3.3.4

7 years ago

4.0.0-alpha.3

7 years ago

3.3.3

7 years ago

4.0.0-alpha.2

7 years ago

4.0.0-alpha

7 years ago

3.3.3-beta.2

7 years ago

3.3.0

7 years ago

3.3.0-beta.8

7 years ago

3.3.0-beta.7

7 years ago

3.3.0-beta.6

7 years ago

3.3.0-beta.5

7 years ago

3.3.0-beta.4

7 years ago

3.3.0-beta.3

7 years ago

3.3.0-beta.2

7 years ago

3.3.0-beta.1

7 years ago

3.2.0

7 years ago

3.2.0-beta.1

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.1.1-beta.3

7 years ago

3.1.1-beta.2

7 years ago

3.1.1-beta.1

7 years ago

3.1.0-beta.1

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

8 years ago

3.0.0-beta.3

8 years ago

3.0.0-beta.2

8 years ago

3.0.0-beta.1

8 years ago