Repository: jdrouet/mrml (language: rust)

Issue:
MRML panics when using mj-divider inside mj-text
Hi!

We recently noticed that MRML is panicking, when we use `<mj-divider>` inside `<mj-text>`. It is reproducable with the following MJML:

```mjml
<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text>
          <mj-divider></mj-divider>
        </mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>
```

It panics with:

```
thread 'main' panicked at mrml-4.0.1/src/mj_divider/render.rs:34:61:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x5a5d9fb00ff5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5380d7966cb17a9f
   1:     0x5a5d9fb28bd3 - core::fmt::write::h6fa818808d2fec0f
   2:     0x5a5d9fafdc5f - std::io::Write::write_fmt::hbfd4c6dab598cc2c
   3:     0x5a5d9fb00e00 - std::sys_common::backtrace::print::hb21cc8c989d23e92
   4:     0x5a5d9fb020b5 - std::panicking::default_hook::{{closure}}::h51c1387cbe610b14
   5:     0x5a5d9fb01e0d - std::panicking::default_hook::hb83d6607ca85d71e
   6:     0x5a5d9fb02544 - std::panicking::rust_panic_with_hook::h31c39679964b4a51
   7:     0x5a5d9fb023eb - std::panicking::begin_panic_handler::{{closure}}::hc9bfccb70659e9b8
   8:     0x5a5d9fb014e9 - std::sys_common::backtrace::__rust_end_short_backtrace::h075f1cf7d2316222
   9:     0x5a5d9fb02177 - rust_begin_unwind
  10:     0x5a5d9f7d01e3 - core::panicking::panic_fmt::hd482fa9e8da4b1ed
  11:     0x5a5d9f7d028c - core::panicking::panic::h5ebb97ce3fdc8cc6
  12:     0x5a5d9f7d0189 - core::option::unwrap_failed::h95d864315f6c4c63
  13:     0x5a5d9f958452 - mrml::mj_divider::render::<impl mrml::prelude::render::Renderer<mrml::mj_divider::MjDivider,()>>::get_outlook_width::ha459ee01adf0ba30
  14:     0x5a5d9f9587b2 - mrml::mj_divider::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mj_divider::MjDivider,()>>::render::h02e7c4d8e0080e40
  15:     0x5a5d9f97d627 - mrml::mj_text::render::<impl mrml::prelude::render::Renderer<mrml::mj_text::MjText,()>>::render_content::hb2b3fd75d53f76b8
  16:     0x5a5d9f97dd24 - mrml::mj_text::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mj_text::MjText,()>>::render::h40d6a44d6d78893b
  17:     0x5a5d9f95597b - mrml::mj_column::render::<impl mrml::prelude::render::Renderer<mrml::mj_column::MjColumn,mrml::mj_column::render::MjColumnExtra>>::render_column::h654dc8e691f00fca
  18:     0x5a5d9f957b7b - mrml::mj_column::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mj_column::MjColumn,mrml::mj_column::render::MjColumnExtra>>::render::h30506b30a7e4c00c
  19:     0x5a5d9f96fa2e - mrml::mj_section::render::SectionLikeRender::render_wrapped_children::hb82e5e6f22d3ccce
  20:     0x5a5d9f973327 - mrml::mj_section::render::SectionLikeRender::render_section::h3fc4e8da1c3d07f2
  21:     0x5a5d9f975800 - mrml::mj_section::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mj_section::MjSection,()>>::render::hbb6f58df474c31b4
  22:     0x5a5d9f944813 - mrml::mj_body::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mj_body::MjBody,()>>::render::h01322d76b229c5e4
  23:     0x5a5d9f9824bc - mrml::mjml::render::<impl mrml::prelude::render::Render for mrml::prelude::render::Renderer<mrml::mjml::Mjml,()>>::render::h6e38890b7ff5b7e6
  24:     0x5a5d9f92aac9 - mrml::mjml::render::<impl mrml::mjml::Mjml>::render::h91b9362809157b27
  25:     0x5a5d9f7f42e2 - mrml::main::h4221d81053c67f42
  26:     0x5a5d9f8219a3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h2e892df33ae86956
  27:     0x5a5d9f8316a9 - std::rt::lang_start::{{closure}}::h542e0133c458501e
  28:     0x5a5d9faf737f - std::rt::lang_start_internal::h0ae654f50e15aeea
  29:     0x5a5d9f7f8f55 - main
  30:     0x70f505b21e08 - <unknown>
  31:     0x70f505b21ecc - __libc_start_main
  32:     0x5a5d9f7d0895 - _start
  33:                0x0 - <unknown>
```

The Javascript implemention renders it without errors.



Discussion / hints:
This actually not supposed to work.
When you run it against the last version of `mjml`, you get the following html template

```html
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
  <title></title>
  <!--[if !mso]><!-->
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <!--<![endif]-->
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style type="text/css">
    #outlook a {
      padding: 0;
    }

    body {
      margin: 0;
      padding: 0;
      -webkit-text-size-adjust: 100%;
      -ms-text-size-adjust: 100%;
    }

    table,
    td {
      border-collapse: collapse;
      mso-table-lspace: 0pt;
      mso-table-rspace: 0pt;
    }

    img {
      border: 0;
      height: auto;
      line-height: 100%;
      outline: none;
      text-decoration: none;
      -ms-interpolation-mode: bicubic;
    }

    p {
      display: block;
      margin: 13px 0;
    }

  </style>
  <!--[if mso]>
    <noscript>
    <xml>
    <o:OfficeDocumentSettings>
      <o:AllowPNG/>
      <o:PixelsPerInch>96</o:PixelsPerInch>
    </o:OfficeDocumentSettings>
    </xml>
    </noscript>
    <![endif]-->
  <!--[if lte mso 11]>
    <style type="text/css">
      .mj-outlook-group-fix { width:100% !important; }
    </style>
    <![endif]-->
  <!--[if !mso]><!-->
  <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
  <style type="text/css">
    @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);

  </style>
  <!--<![endif]-->
  <style type="text/css">
    @media only screen and (min-width:480px) {
      .mj-column-per-100 {
        width: 100% !important;
        max-width: 100%;
      }
    }

  </style>
  <style media="screen and (min-width:480px)">
    .moz-text-html .mj-column-per-100 {
      width: 100% !important;
      max-width: 100%;
    }

  </style>
</head>

<body style="word-spacing:normal;">
  <div style="">
    <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" role="presentation" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
    <div style="margin:0px auto;max-width:600px;">
      <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
        <tbody>
          <tr>
            <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
              <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->
              <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
                <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
                  <tbody>
                    <tr>
                      <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
                        <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;"><mj-divider></mj-divider></div>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <!--[if mso | IE]></td></tr></table><![endif]-->
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!--[if mso | IE]></td></tr></table><![endif]-->
  </div>
</body>

</html>
```

You can see the `<mj-divider></mj-divider>` was just left like this.

That being said, `mrml` should behave the same.

Fix patch:
diff --git a/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.html b/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.html
new file mode 100644
index 00000000..e5965df3
--- /dev/null
+++ b/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.html
@@ -0,0 +1,115 @@
+<!doctype html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
+
+<head>
+  <title></title>
+  <!--[if !mso]><!-->
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <!--<![endif]-->
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <style type="text/css">
+    #outlook a {
+      padding: 0;
+    }
+
+    body {
+      margin: 0;
+      padding: 0;
+      -webkit-text-size-adjust: 100%;
+      -ms-text-size-adjust: 100%;
+    }
+
+    table,
+    td {
+      border-collapse: collapse;
+      mso-table-lspace: 0pt;
+      mso-table-rspace: 0pt;
+    }
+
+    img {
+      border: 0;
+      height: auto;
+      line-height: 100%;
+      outline: none;
+      text-decoration: none;
+      -ms-interpolation-mode: bicubic;
+    }
+
+    p {
+      display: block;
+      margin: 13px 0;
+    }
+
+  </style>
+  <!--[if mso]>
+    <noscript>
+    <xml>
+    <o:OfficeDocumentSettings>
+      <o:AllowPNG/>
+      <o:PixelsPerInch>96</o:PixelsPerInch>
+    </o:OfficeDocumentSettings>
+    </xml>
+    </noscript>
+    <![endif]-->
+  <!--[if lte mso 11]>
+    <style type="text/css">
+      .mj-outlook-group-fix { width:100% !important; }
+    </style>
+    <![endif]-->
+  <!--[if !mso]><!-->
+  <link href="https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700" rel="stylesheet" type="text/css">
+  <style type="text/css">
+    @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
+
+  </style>
+  <!--<![endif]-->
+  <style type="text/css">
+    @media only screen and (min-width:480px) {
+      .mj-column-per-100 {
+        width: 100% !important;
+        max-width: 100%;
+      }
+    }
+
+  </style>
+  <style media="screen and (min-width:480px)">
+    .moz-text-html .mj-column-per-100 {
+      width: 100% !important;
+      max-width: 100%;
+    }
+
+  </style>
+</head>
+
+<body style="word-spacing:normal;">
+  <div style="">
+    <!--[if mso | IE]><table align="center" border="0" cellpadding="0" cellspacing="0" class="" role="presentation" style="width:600px;" width="600" ><tr><td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;"><![endif]-->
+    <div style="margin:0px auto;max-width:600px;">
+      <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
+        <tbody>
+          <tr>
+            <td style="direction:ltr;font-size:0px;padding:20px 0;text-align:center;">
+              <!--[if mso | IE]><table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td class="" style="vertical-align:top;width:600px;" ><![endif]-->
+              <div class="mj-column-per-100 mj-outlook-group-fix" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
+                <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="vertical-align:top;" width="100%">
+                  <tbody>
+                    <tr>
+                      <td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
+                        <div style="font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:13px;line-height:1;text-align:left;color:#000000;"><mj-divider></mj-divider></div>
+                      </td>
+                    </tr>
+                  </tbody>
+                </table>
+              </div>
+              <!--[if mso | IE]></td></tr></table><![endif]-->
+            </td>
+          </tr>
+        </tbody>
+      </table>
+    </div>
+    <!--[if mso | IE]></td></tr></table><![endif]-->
+  </div>
+</body>
+
+</html>
diff --git a/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.mjml b/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.mjml
new file mode 100644
index 00000000..94626b6c
--- /dev/null
+++ b/packages/mrml-core/resources/compare/success/mj-divider-in-mj-text.mjml
@@ -0,0 +1,11 @@
+<mjml>
+    <mj-body>
+        <mj-section>
+            <mj-column>
+                <mj-text>
+                    <mj-divider></mj-divider>
+                </mj-text>
+            </mj-column>
+        </mj-section>
+    </mj-body>
+</mjml>
diff --git a/packages/mrml-core/src/mj_text/mod.rs b/packages/mrml-core/src/mj_text/mod.rs
index 2687380f..ad768b22 100644
--- a/packages/mrml-core/src/mj_text/mod.rs
+++ b/packages/mrml-core/src/mj_text/mod.rs
@@ -1,6 +1,6 @@
 use std::marker::PhantomData;
 
-use crate::mj_body::MjBodyChild;
+use crate::mj_raw::MjRawChild;
 use crate::prelude::{Component, StaticTag};
 
 #[cfg(feature = "json")]
@@ -22,4 +22,4 @@ impl StaticTag for MjTextTag {
     }
 }
 
-pub type MjText = Component<PhantomData<MjTextTag>, crate::prelude::AttributeMap, Vec<MjBodyChild>>;
+pub type MjText = Component<PhantomData<MjTextTag>, crate::prelude::AttributeMap, Vec<MjRawChild>>;


Test patch: