Don't render empty attributes when stringifying.

This commit is contained in:
Bodil Stokke 2019-04-08 16:44:34 +01:00
parent 91c3d9864a
commit ccb00646ac
1 changed files with 4 additions and 2 deletions

View File

@ -337,8 +337,10 @@ impl Declare {
for (attr_name, _, attr_str) in self.attrs() { for (attr_name, _, attr_str) in self.attrs() {
print_attrs.extend(quote!( print_attrs.extend(quote!(
if let Some(ref value) = self.attrs.#attr_name { if let Some(ref value) = self.attrs.#attr_name {
write!(f, " {}=\"{}\"", #attr_str, let value = ::htmlescape::encode_attribute(&value.to_string());
::htmlescape::encode_attribute(&value.to_string()))?; if !value.is_empty() {
write!(f, " {}=\"{}\"", #attr_str, value)?;
}
} }
)); ));
} }