GrapesJS / mjml

Newsletter Builder with MJML components in GrapesJS
http://grapesjs.com/demo-mjml.html
BSD 3-Clause "New" or "Revised" License
634 stars 226 forks source link

Question: MJML Validation #218

Closed HeyWrecker closed 1 month ago

HeyWrecker commented 3 years ago

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

DRoet commented 3 years ago

You are right there is currently no way to call the validation manually

HeyWrecker commented 3 years ago

@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.

DRoet commented 3 years ago

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);
})
HeyWrecker commented 3 years ago

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.

artf commented 1 month ago

The plugin provides a command that could be used to run mjml2html programmatically editor.runCommand('mjml-code-to-html')