summary refs log tree commit diff
path: root/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/render.rs')
-rw-r--r--src/render.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/render.rs b/src/render.rs
index 73e1a5e..691f778 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -33,6 +33,11 @@ pub enum RenderNode {
     Null,
 }
 
+const VOID_TAGS: [&str; 14] = [
+    "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source",
+    "track", "wbr",
+];
+
 impl RenderNode {
     pub(crate) fn render_to_string(self) -> Pin<Box<dyn Future<Output = String>>> {
         match self {
@@ -76,8 +81,18 @@ impl RenderNode {
                         .map(|child| child.render_to_string())
                         .collect::<Vec<_>>()).await.join("");
 
-                    format!("<{name}{text_attributes}>{rendered_children}</{name}>")
+                    let is_void = VOID_TAGS.iter().any(|&s| s == name);
+                    let has_children = rendered_children.trim() != "";
+
+                    if has_children && is_void {
+                        eprintln!("WARN: <{name}/> is a void tag, and should not have children");
+                    }
 
+                    if !has_children && is_void {
+                        format!("<{name}{text_attributes}/>")
+                    } else {
+                        format!("<{name}{text_attributes}>{rendered_children}</{name}>")
+                    }
                 })
             },
             RenderNode::Fragment { children } => {