Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML minification parser error #1527

Closed
timc13 opened this issue Feb 21, 2019 · 7 comments
Closed

HTML minification parser error #1527

timc13 opened this issue Feb 21, 2019 · 7 comments

Comments

@timc13
Copy link

timc13 commented Feb 21, 2019

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>
  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
@iRyusa
Copy link
Member

iRyusa commented Feb 21, 2019 via email

@timc13
Copy link
Author

timc13 commented Feb 21, 2019

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

@iRyusa
Copy link
Member

iRyusa commented Feb 25, 2019

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

@kmcb777
Copy link
Collaborator

kmcb777 commented Mar 26, 2019

@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
Copy link
Member

iRyusa commented Mar 26, 2019

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

@timc13
Copy link
Author

timc13 commented Mar 26, 2019

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
Copy link
Member

iRyusa commented Mar 26, 2019

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

iRyusa added a commit that referenced this issue Apr 3, 2019
fix #1527 doc to ignore content during minification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants