Package Exports
- mjml-validator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mjml-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mjml-validator
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 (default): 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
In CLI
When using the mjml command line, you can add the option -l or --level with the validation level you want. Ex: mjml -l strict -r my_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:
getErrorsreturns an array of objects withline,message,tagNameas well as aformattedMessagewhich contains theline,messageandtagNameconcatenated in a sentence.getMessagesreturns an array offormattedMessage.
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.