jdrouet/mrml

Support parsing elements with no closing tag

DGulshan opened this issue · 9 comments

I am trying to parse MJML that includes <br> tags, but I get the following error: invalid format. JavaScript parser for MJML doesn't seem to have to this issue. For example, the following MJML renders without any issues on https://mjml.io/try-it-live:

<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text><br>Some Test Content</mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>

It works when I replace <br> with <br/> but I am trying to parse some external templates and in some of these templates, <br> tags have additional data attributes, so I can't do a simple find and replace.

Please let me know if this can be supported.

Hi! Thank you for your issue.
This comes from the library I use to parse the template: xmlparser. <br> without a closing </br> is not a valid XML element BUT is still valid in HTML.
To fix that bug, I'd need to use a completely different XML parser which is out of scope for now.

Alright! Thanks for letting me know.

@jdrouet Thanks for the amazing crate! ❤️ Would love to pick your brain a bit more on this:

  1. As per the MJML docs, only mj-raw and mj-text tags allow HTML. Would it be better to:
    (a) use an HTML parser only for the children of mj-raw & mj-text? (OR)
    (b) replace xmlparser completely with an HTML parser?
  2. Would html5ever be a good HTML parser to use?
  3. Would you be open to merging a pull request with these changes?

Appreciate your time.

Bump, Imo i think there's valid need for these. If @jdrouet can propose a direction, maybe migrating to a different parser can be work on :)

@jdrouet would (some?) other void elements also needed to be ignored similar to br and meta? E.g. <hr> comes to mind, which might be used one or the other time.

https://html.spec.whatwg.org/multipage/syntax.html#void-elements

@paulgoetze thanks for finding this! I'll update it!

@paulgoetze done and released ;)