jdrouet / mrml

Implementation of mjml in rust
MIT License
322 stars 19 forks source link

Self-closing empty nodes in mj-raw results in invalid HTML #406

Closed stefan-as closed 3 months ago

stefan-as commented 3 months ago

MRML rewrites empty HTML nodes <node></node> within an <mj-raw> section into a self closing format <node />. But not all HTML elements are allowed to be self closed, e.q. the <div> element, as mentioned in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div

"Tag omission: None, both the starting and ending tag are mandatory."

This behavior leads to broken results, as shown in the following example:

<mj-raw>
  <div style="display: none"></div>
  <div>Foo</div>
<mj-raw>

parsed by mrml into

<div>
  <div style="display: none" />
  <div>Foo</div>
</div>

resulting in the following DOM rendered by chrome browser

<div>
  <div style="display: none">
    <div>Foo</div>
  </div>
</div>

The original MJML parser does not self close empty nodes and renders output in a proper way.