diff --git a/plait-macros/src/buffer.rs b/plait-macros/src/buffer.rs index 91a2014..d5025dc 100644 --- a/plait-macros/src/buffer.rs +++ b/plait-macros/src/buffer.rs @@ -349,7 +349,13 @@ impl InnerBuffer { children, } = element; - self.static_str.push_str(&format!("<{}", tag.value())); + let tag_str = tag.value(); + + if tag_str == "html" && !self.static_str.ends_with("") { + self.static_str.push_str(""); + } + + self.static_str.push_str(&format!("<{}", tag_str)); for attribute in attributes { self.push_attribute(attribute); @@ -357,9 +363,9 @@ impl InnerBuffer { self.static_str.push('>'); - if !is_void_element(&tag.value()) { + if !is_void_element(&tag_str) { self.push_block(children); - self.static_str.push_str(&format!("", tag.value())); + self.static_str.push_str(&format!("", tag_str)); } } diff --git a/plait/tests/html_macro_tests.rs b/plait/tests/html_macro_tests.rs index bdab964..3097227 100644 --- a/plait/tests/html_macro_tests.rs +++ b/plait/tests/html_macro_tests.rs @@ -49,6 +49,22 @@ fn test_html_macro_doctype() { assert_eq!(html.to_html(), "") } +#[test] +fn test_html_macro_auto_doctype() { + let html = html! { + #doctype + html {} + }; + + assert_eq!(html.to_html(), ""); + + let html = html! { + html {} + }; + + assert_eq!(html.to_html(), ""); +} + #[test] fn test_html_macro_let_binding() { let world = " World";