Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions plait-macros/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,23 @@ 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("<!DOCTYPE html>") {
self.static_str.push_str("<!DOCTYPE html>");
}

self.static_str.push_str(&format!("<{}", tag_str));

for attribute in attributes {
self.push_attribute(attribute);
}

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));
}
}

Expand Down
16 changes: 16 additions & 0 deletions plait/tests/html_macro_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ fn test_html_macro_doctype() {
assert_eq!(html.to_html(), "<!DOCTYPE html>")
}

#[test]
fn test_html_macro_auto_doctype() {
let html = html! {
#doctype
html {}
};

assert_eq!(html.to_html(), "<!DOCTYPE html><html></html>");

let html = html! {
html {}
};

assert_eq!(html.to_html(), "<!DOCTYPE html><html></html>");
}

#[test]
fn test_html_macro_let_binding() {
let world = " World";
Expand Down