Issue #3441Opened May 7, 2021by emilsedgh1 reactions

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:

  1. It will render the style like this:
@font-face {font-family: &quot;foo&quot;;src: url(&#039;./fonts/foo&#039;) format(&#039;truetype&#039;);}
  1. When you export the code, it exports the MJML code as the following:
<mjml>
  <mj-head>
    <mj-style>
      @font-face {
      font-family: &quot;foo&quot;;src: url(&#039;./fonts/foo.otf&#039;) format(&#039;truetype&#039;);
      }
    </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?

3

Answers (3)

emilsedghAugust 3, 20211 reactions

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.

artfAugust 3, 20210 reactions

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>`;
    }
    // ...
  }
})
artfAugust 3, 20210 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.