mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
17.08k stars 960 forks source link

HTML minification parser error #1527

Closed timc13 closed 5 years ago

timc13 commented 5 years ago

Describe the bug HTML minification breaks if there is a < in a <mj-raw> section.

To Reproduce Steps to reproduce the behavior:

  1. Create a file with this MJML code:
    <mjml>
    <mj-body>
    <mj-section>
      <mj-column>
        <mj-raw>
          {% if foo < 5 %}
          {% endif %}
        </mj-raw>
        <mj-text>Hello World</mj-text>
      </mj-column>
    </mj-section>
    </mj-body>
    </mjml>
  2. compile using the API:
    const output = mjml2html(file.contents.toString(), {
    minify: true,
    filePath: file.path,
    })
  3. See error:
    Error: Parse Error: < 5 %}

Expected behavior Expected minified HTML to succeed

MJML environment (please complete the following information):

iRyusa commented 5 years ago

I don't think we'll be able to do something about this as we use an external lib to provide the minification :/ maybe wrap everything into html comment ?

On Thu, Feb 21, 2019 at 5:40 PM Tim Chen notifications@github.com wrote:

Describe the bug HTML minification breaks if there is a < in a section.

To Reproduce Steps to reproduce the behavior:

  1. Create a file with this MJML code:
{% if foo < 5 %} {% endif %} Hello World
  1. compile using the API:

const output = mjml2html(file.contents.toString(), { minify: true, filePath: file.path, })

  1. See error:

Error: Parse Error: < 5 %}

Expected behavior Expected minified HTML to succeed

MJML environment (please complete the following information):

  • OS: MacOS 10.14.3
  • MJML API Version 4.3.1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mjmlio/mjml/issues/1527, or mute the thread https://github.com/notifications/unsubscribe-auth/AAizzUxMA5PXbORsYCqyxtiWzrHEET14ks5vPsv-gaJpZM4bH2rS .

-- Cordialement, Maxime BRAZEILLES

timc13 commented 5 years ago

found an answer: https://github.com/kangax/html-minifier#ignoring-chunks-of-markup. might be worth mentioning in the documentation of mj-raw

iRyusa commented 5 years ago

Maybe it would be great to add those automatically when using mj-raw + minify option cc @kmcb777

kmcb777 commented 5 years ago

@iRyusa I tested using this html-minifier feature and it works well It would be much cleaner to apply this on all endingTags instead of just mj-raw, so that we can handle this on the parser. On the other hand, it will prevent minification of all the endingTags content. People often use html in those, and will probably want to have it minified, so maybe we should add an option ?

iRyusa commented 5 years ago

Maybe @timc13 solution is better then, let's mention it to the doc instead 🤔

timc13 commented 5 years ago

what about this idea:

add an attribute to mj-raw instructing the parser to inject the htmlmin:ignore tag.

<mj-raw ignore-min>
</mj-raw>
iRyusa commented 5 years ago

That could be done too but as minify is optional it's a bit weird to have attribute for a potential option ?