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"/>
|
<link rel=LinkType::StyleSheet href="lol.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div></div>
|
||||||
<h1 data-lol="omg">"Hello Kitty!"</h1>
|
<h1 data-lol="omg">"Hello Kitty!"</h1>
|
||||||
<p class="official-position-of-sanrio-ltd emphasis">
|
<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>"."
|
"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
|
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!
|
// This NEEDS to be a sorted list!
|
||||||
pub static ATTR_EVENTS: &[&str] = &[
|
pub static ATTR_EVENTS: &[&str] = &[
|
||||||
"abort",
|
"abort",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use proc_macro2::{Ident, Literal, Span, TokenStream, TokenTree};
|
use proc_macro2::{Ident, Literal, Span, TokenStream, TokenTree};
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
use config::{global_attrs, ATTR_EVENTS};
|
use config::{global_attrs, ATTR_EVENTS, SELF_CLOSING};
|
||||||
use error::ParseError;
|
use error::ParseError;
|
||||||
use ident;
|
use ident;
|
||||||
use lexer::{Lexer, Token};
|
use lexer::{Lexer, Token};
|
||||||
|
@ -284,15 +284,29 @@ impl Declare {
|
||||||
|
|
||||||
let print_children = if self.req_children.is_empty() {
|
let print_children = if self.req_children.is_empty() {
|
||||||
if self.opt_children.is_some() {
|
if self.opt_children.is_some() {
|
||||||
quote!(if self.children.is_empty() {
|
if !SELF_CLOSING.contains(&elem_name.to_string().as_str()) {
|
||||||
write!(f, "/>")
|
quote!(if self.children.is_empty() {
|
||||||
|
write!(f, "></{}>", #name)
|
||||||
|
} else {
|
||||||
|
write!(f, ">")?;
|
||||||
|
#print_opt_children
|
||||||
|
write!(f, "</{}>", #name)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
write!(f, ">")?;
|
quote!(if self.children.is_empty() {
|
||||||
#print_opt_children
|
write!(f, " />")
|
||||||
write!(f, "</{}>", #name)
|
} else {
|
||||||
})
|
write!(f, ">")?;
|
||||||
|
#print_opt_children
|
||||||
|
write!(f, "</{}>", #name)
|
||||||
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
quote!(write!(f, "/>"))
|
if !SELF_CLOSING.contains(&elem_name.to_string().as_str()) {
|
||||||
|
quote!(write!(f, "></{}>", #name))
|
||||||
|
} else {
|
||||||
|
quote!(write!(f, "/>"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote!(
|
quote!(
|
||||||
|
|
Loading…
Reference in New Issue