mjml-validator
mjml-validator
npm i mjml-validator
mjml-validator

mjml-validator

MJML: the only framework that makes responsive-email easy

by mjmlio

4.13.0 (see all)License:MITTypeScript:Not Found
npm i mjml-validator
Readme

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 -c.validationLevel or --config.validationLevel with the validation level you want.

Set the validation level to skip (so that the file is not validated) and render the file

mjml --config.validationLevel=skip template.mjml

Alternatively, you can just validate file without rendering it by add ing the --validate option

mjml --validate template.mjml

In Javascript

In Javascript, you can provide the level through the options parameters on mjml2html. Ex: mjml2html(inputMJML, { validationLevel: '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 in the object returned by mjml2html. It is the same object returned by getErrors on strict mode.

VersionTagPublished
4.13.0
latest
7mos ago
4.7.0-beta.2
next
2yrs ago
4.6.3-alpha.0
experimental
3yrs ago
3.3.3-beta.2
beta
6yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate