BUG: Parser breaks `mj-style` as of 16.30
Question
Version:
All Grapesjs version from 16.30 to now have this issues.
Are you able to reproduce the bug from the demo?
- Yes
- No
What is the expected behavior?
The following is valid MJML code. It should work fine on grapesjs-mjml.
<mjml>
<mj-head>
<mj-style>
@font-face {
font-family: "foo";src: url('./fonts/foo.otf') format('truetype');
}
</mj-style>
</mj-head>
<mj-body>
Describe the bug detailed
Right now, if you use grapesjs-mjml with the code above it will break in 2 ways:
- It will render the style like this:
@font-face {font-family: "foo";src: url('./fonts/foo') format('truetype');}
- When you export the code, it exports the MJML code as the following:
<mjml>
<mj-head>
<mj-style>
@font-face {
font-family: "foo";src: url('./fonts/foo.otf') format('truetype');
}
</mj-style>
</mj-head>
<mj-body>
</mj-body>
</mjml>
In both cases, you can see that the style has been html-encoded.
What is the current behavior?
mj-style is not a textNode and it's content must not be htmlEncoded.
Describe the bug detailed
The reason I'm filing this against this repository and not grapesjs-mjml is this: This regression is a result of commit 8e7f94abb0c4500cebde5a4984eca4215772cb0b.
As of this commit, grapesjs wrongly assumes all textNode's are, well, textNode's. That's not always the case (like mj-style).
Are you able to attach screenshots, screencasts or a live demo?

Answers (3)
Hi Artur. Thank you for the great job done on grapesjs. It really is fantastic.
The interim solution works just fine. Feel free to close out if necessary, but providing a way of manipulating the behavior would definitely be pretty nice.
Hi @emilsedgh I apologize for being so late on this issue, but anyway, we can think about how to skip escape in cases like that but probably the fastest way is to simply extend mj-style toHTML method
editor.Components.addType('mj-style', {
model: {
toHTML() {
const content = this.components().map(c => c.get('content')).join('');
return `<mj-style>${content}</mj-style>`;
}
// ...
}
})
Thanks Emil, for now, I'll close this one, in case another similar issue will arise, we'll think about adding a new prop for skipping the escape.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3316
BUG: The editor does not remove the dead script blocks
Version: 0.16.34 Are you able to reproduce the bug from the demo? [ ] Yes [x ] No As I understand the code import dialog skips all the HTML...
Issue #3015
BUG: HTML exported from the demo not responsive to screen size
Version: 0.16.22 Are you able to reproduce the bug from the demo? [] Yes [ ] No What is the expected behavior? the exported html should be...
Issue #2916
[Bug]: Text component content not retrieved properly when using custom RTE
Version: 0.16.12 Are you able to reproduce the bug from the demo ? [ ] Yes [x] No (it does not include a custom RTE) What is the expected b...
Issue #2887
BUG: Embedding Youtube Playlist Breaks the URL
Version: v.0.16.18 Are you able to reproduce the bug from the demo? [x] Yes [ ] No What is the expected behavior? It should render the play...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.