Closed HeyWrecker closed 1 month ago
You are right there is currently no way to call the validation manually
@DRoet Hi Daan, thank you for the response! Does GrapesJS have it's own implementation of MJML validation independent of the mjml2html()
function that is available? We've run into a situation where individuals are pasting content from word as well as in some cases making incomplete selections and then pasting content into an MJML block and upon inspection, the HTML was missing closing tags and therefore breaking the rest of the email. I checked it out in the MJML Live editor and when the "Beautify" button was pressed, it confirmed what I had manually checked on my own.
no, everything is done by the mjml2html() function, I just checked and we do currently throw errors to the console when importing incorrect mjml code, see: https://github.com/artf/grapesjs-mjml/blob/master/src/command-export-mjml.js#L86
I understand that this is kind of useless for your end users, so we either have to implement a way to return the errors upon import OR you will have to use event listeners and run your own validation upon mjml imports/changes
for example:
editor.on('run:mjml-import:change', (mjml) => {
// run some sort of validation here
console.log(mjml);
})
Got it. Thanks Daan. Without access to the mjml2html()
function that makes the actual manual validation checking difficult. I've been looking around for a stand alone implementation of the function that I can use in the global scope but haven't seen anything yet. Maybe I'm just not looking in the right places.
The plugin provides a command that could be used to run mjml2html programmatically editor.runCommand('mjml-code-to-html')
The
mjml2html()
function allows for validation via a passed argument and will return errors if the mjml doesn't validate. If I'm not mistaken GrapesJS-MJML is using the function internally, but is there a way to specifically call for validation through GrapesJS-MJML or is there a way to access this function directly? I'm using the compiled version of the library obtained through a CDN, not a built from source version.Thanks!
Rick