auto-close elements with no child

This commit is contained in:
Emmanuel Gil Peyrot 2017-03-31 17:01:48 +01:00
parent f301f2cb10
commit 9af7d252d7

View file

@ -38,18 +38,23 @@ impl fmt::Debug for Element {
for attr in &self.attributes {
write!(fmt, " {}", attr)?;
}
write!(fmt, ">")?;
for child in &self.children {
match *child {
Node::Element(ref e) => {
write!(fmt, "{:?}", e)?;
},
Node::Text(ref s) => {
write!(fmt, "{}", s)?;
},
}
if self.children.is_empty() {
write!(fmt, "/>")?;
}
else {
write!(fmt, ">")?;
for child in &self.children {
match *child {
Node::Element(ref e) => {
write!(fmt, "{:?}", e)?;
},
Node::Text(ref s) => {
write!(fmt, "{}", s)?;
},
}
}
write!(fmt, "</{}>", self.name)?;
}
write!(fmt, "</{}>", self.name)?;
Ok(())
}
}