Repository: jdrouet/mrml (language: rust)

Issue:
mj-style is not outputting start and end style tags
When using the mj-style tag with no attributes:

`  <mj-style>
    a {}
    p {}
    h1 {}
    h2 {}
    h3 {}
    button {}
  </mj-style>`

The output is put into the html head but without any surrounding <style></style> tags.

`   a {}
    p {}
    h1 {}
    h2 {}
    h3 {}
    button {}
`


Discussion / hints:

Fix patch:
diff --git a/packages/mrml-core/src/mj_head/render.rs b/packages/mrml-core/src/mj_head/render.rs
index 48936aa3..cf609a1d 100644
--- a/packages/mrml-core/src/mj_head/render.rs
+++ b/packages/mrml-core/src/mj_head/render.rs
@@ -227,28 +227,36 @@ impl<'e, 'h> MJHeadRender<'e, 'h> {
 
     fn render_styles(&self) -> String {
         let header = self.header.borrow();
-        if header.styles().is_empty() {
-            return String::default();
-        }
-        let mut buf = self
-            .element
-            .children
-            .iter()
-            .filter_map(|child| child.as_mj_style())
-            .map(|child| child.children())
-            .collect::<Vec<_>>()
-            .join("\n");
-        if !header.styles().is_empty() {
-            if !buf.is_empty() {
-                buf.push('\n');
+        let header_styles = {
+            if header.styles().is_empty() {
+                String::default()
+            } else {
+                let mut buf = "<style type=\"text/css\">".to_string();
+                header.styles().iter().for_each(|style| {
+                    buf.push_str(style);
+                });
+                buf.push_str("</style>");
+                buf
             }
-            buf.push_str("<style type=\"text/css\">");
-            header.styles().iter().for_each(|style| {
-                buf.push_str(style);
-            });
-            buf.push_str("</style>");
-        }
-        buf
+        };
+        let head_styles = {
+            let buf = self
+                .element
+                .children
+                .iter()
+                .filter_map(|child| child.as_mj_style())
+                .map(|child| child.children())
+                .collect::<Vec<_>>()
+                .join("\n");
+            if buf.is_empty() {
+                buf
+            } else {
+                format!("<style type=\"text/css\">{}</style>", buf)
+            }
+        };
+        format!("{}\n{}", header_styles, head_styles)
+            .trim()
+            .to_string()
     }
 }
 
@@ -290,3 +298,20 @@ impl<'r, 'e: 'r, 'h: 'r> Renderable<'r, 'e, 'h> for MJHead {
         })
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use crate::helper::test::compare;
+    use crate::mjml::MJML;
+    use crate::prelude::render::Options;
+
+    #[test]
+    fn basic() {
+        let opts = Options::default();
+        let template = include_str!("../../resources/compare/success/mj-style.mjml");
+        let expected = include_str!("../../resources/compare/success/mj-style.html");
+        let root = MJML::parse(template.to_string()).unwrap();
+        let result = root.render(&opts).unwrap();
+        compare(expected, result.as_str());
+    }
+}
diff --git a/resources/compare/success/mj-style.html b/resources/compare/success/mj-style.html
index 80af9499..0de69354 100644
--- a/resources/compare/success/mj-style.html
+++ b/resources/compare/success/mj-style.html
@@ -76,8 +76,6 @@
       max-width: 100%;
     }
   </style>
-  <style type="text/css">
-  </style>
   <style type="text/css">
     .red-text div {
       color: red !important;


Test patch: