Support allow list of self-closing tags. Fixes #15
This commit is contained in:
parent
28bc92ebc7
commit
7cb9441820
|
@ -33,6 +33,7 @@ fn index() -> Html {
|
|||
<link rel=LinkType::StyleSheet href="lol.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div></div>
|
||||
<h1 data-lol="omg">"Hello Kitty!"</h1>
|
||||
<p class="official-position-of-sanrio-ltd emphasis">
|
||||
"She is not a "<em><a href="https://en.wikipedia.org/wiki/Cat">"cat"</a></em>". She is a "<em>"human girl"</em>"."
|
||||
|
|
|
@ -37,6 +37,25 @@ pub fn global_attrs(span: Span) -> StringyMap<Ident, TokenStream> {
|
|||
attrs
|
||||
}
|
||||
|
||||
pub static SELF_CLOSING: &[&str] = &[
|
||||
"area",
|
||||
"base",
|
||||
"br",
|
||||
"col",
|
||||
"command",
|
||||
"embed",
|
||||
"hr",
|
||||
"img",
|
||||
"input",
|
||||
"keygen",
|
||||
"link",
|
||||
"meta",
|
||||
"param",
|
||||
"source",
|
||||
"track",
|
||||
"wbr",
|
||||
];
|
||||
|
||||
// This NEEDS to be a sorted list!
|
||||
pub static ATTR_EVENTS: &[&str] = &[
|
||||
"abort",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use proc_macro2::{Ident, Literal, Span, TokenStream, TokenTree};
|
||||
use quote::quote;
|
||||
|
||||
use config::{global_attrs, ATTR_EVENTS};
|
||||
use config::{global_attrs, ATTR_EVENTS, SELF_CLOSING};
|
||||
use error::ParseError;
|
||||
use ident;
|
||||
use lexer::{Lexer, Token};
|
||||
|
@ -284,15 +284,29 @@ impl Declare {
|
|||
|
||||
let print_children = if self.req_children.is_empty() {
|
||||
if self.opt_children.is_some() {
|
||||
quote!(if self.children.is_empty() {
|
||||
write!(f, "/>")
|
||||
if !SELF_CLOSING.contains(&elem_name.to_string().as_str()) {
|
||||
quote!(if self.children.is_empty() {
|
||||
write!(f, "></{}>", #name)
|
||||
} else {
|
||||
write!(f, ">")?;
|
||||
#print_opt_children
|
||||
write!(f, "</{}>", #name)
|
||||
})
|
||||
} else {
|
||||
write!(f, ">")?;
|
||||
#print_opt_children
|
||||
write!(f, "</{}>", #name)
|
||||
})
|
||||
quote!(if self.children.is_empty() {
|
||||
write!(f, " />")
|
||||
} else {
|
||||
write!(f, ">")?;
|
||||
#print_opt_children
|
||||
write!(f, "</{}>", #name)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
quote!(write!(f, "/>"))
|
||||
if !SELF_CLOSING.contains(&elem_name.to_string().as_str()) {
|
||||
quote!(write!(f, "></{}>", #name))
|
||||
} else {
|
||||
quote!(write!(f, "/>"))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote!(
|
||||
|
|
Loading…
Reference in New Issue