2021-03-08 02:28:20 +00:00
|
|
|
// use lazy_static::lazy_static;
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
use std::collections::hash_set::HashSet;
|
2021-06-03 14:42:28 +00:00
|
|
|
use syn::{parse::ParseBuffer, Expr};
|
|
|
|
|
|
|
|
pub fn try_parse_bracketed(stream: &ParseBuffer) -> syn::Result<Expr> {
|
|
|
|
let content;
|
|
|
|
syn::braced!(content in stream);
|
|
|
|
content.parse()
|
|
|
|
}
|
2021-03-08 02:28:20 +00:00
|
|
|
|
2021-05-31 22:55:56 +00:00
|
|
|
/// rsx! and html! macros support the html namespace as well as svg namespace
|
|
|
|
static HTML_TAGS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
|
2021-03-08 02:28:20 +00:00
|
|
|
[
|
|
|
|
"a",
|
|
|
|
"abbr",
|
|
|
|
"address",
|
|
|
|
"area",
|
|
|
|
"article",
|
|
|
|
"aside",
|
|
|
|
"audio",
|
|
|
|
"b",
|
|
|
|
"base",
|
|
|
|
"bdi",
|
|
|
|
"bdo",
|
|
|
|
"big",
|
|
|
|
"blockquote",
|
|
|
|
"body",
|
|
|
|
"br",
|
|
|
|
"button",
|
|
|
|
"canvas",
|
|
|
|
"caption",
|
|
|
|
"cite",
|
|
|
|
"code",
|
|
|
|
"col",
|
|
|
|
"colgroup",
|
|
|
|
"command",
|
|
|
|
"data",
|
|
|
|
"datalist",
|
|
|
|
"dd",
|
|
|
|
"del",
|
|
|
|
"details",
|
|
|
|
"dfn",
|
|
|
|
"dialog",
|
|
|
|
"div",
|
|
|
|
"dl",
|
|
|
|
"dt",
|
|
|
|
"em",
|
|
|
|
"embed",
|
|
|
|
"fieldset",
|
|
|
|
"figcaption",
|
|
|
|
"figure",
|
|
|
|
"footer",
|
|
|
|
"form",
|
|
|
|
"h1",
|
|
|
|
"h2",
|
|
|
|
"h3",
|
|
|
|
"h4",
|
|
|
|
"h5",
|
|
|
|
"h6",
|
|
|
|
"head",
|
|
|
|
"header",
|
|
|
|
"hr",
|
|
|
|
"html",
|
|
|
|
"i",
|
|
|
|
"iframe",
|
|
|
|
"img",
|
|
|
|
"input",
|
|
|
|
"ins",
|
|
|
|
"kbd",
|
|
|
|
"keygen",
|
|
|
|
"label",
|
|
|
|
"legend",
|
|
|
|
"li",
|
|
|
|
"link",
|
|
|
|
"main",
|
|
|
|
"map",
|
|
|
|
"mark",
|
|
|
|
"menu",
|
|
|
|
"menuitem",
|
|
|
|
"meta",
|
|
|
|
"meter",
|
|
|
|
"nav",
|
|
|
|
"noscript",
|
|
|
|
"object",
|
|
|
|
"ol",
|
|
|
|
"optgroup",
|
|
|
|
"option",
|
|
|
|
"output",
|
|
|
|
"p",
|
|
|
|
"param",
|
|
|
|
"picture",
|
|
|
|
"pre",
|
|
|
|
"progress",
|
|
|
|
"q",
|
|
|
|
"rp",
|
|
|
|
"rt",
|
|
|
|
"ruby",
|
|
|
|
"s",
|
|
|
|
"samp",
|
|
|
|
"script",
|
|
|
|
"section",
|
|
|
|
"select",
|
|
|
|
"small",
|
|
|
|
"source",
|
|
|
|
"span",
|
|
|
|
"strong",
|
2021-07-05 05:11:49 +00:00
|
|
|
"style",
|
2021-03-08 02:28:20 +00:00
|
|
|
"sub",
|
|
|
|
"summary",
|
|
|
|
"sup",
|
|
|
|
"table",
|
|
|
|
"tbody",
|
|
|
|
"td",
|
|
|
|
"textarea",
|
|
|
|
"tfoot",
|
|
|
|
"th",
|
|
|
|
"thead",
|
|
|
|
"time",
|
|
|
|
"title",
|
|
|
|
"tr",
|
|
|
|
"track",
|
|
|
|
"u",
|
|
|
|
"ul",
|
|
|
|
"var",
|
|
|
|
"video",
|
|
|
|
"wbr",
|
2021-05-31 22:55:56 +00:00
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.collect()
|
|
|
|
});
|
|
|
|
|
|
|
|
static SVG_TAGS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
|
|
|
|
[
|
2021-05-15 16:03:08 +00:00
|
|
|
// SVTG
|
2021-07-05 22:37:15 +00:00
|
|
|
"svg", "path", "g", "text",
|
2021-03-08 02:28:20 +00:00
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.collect()
|
|
|
|
});
|
|
|
|
|
2021-06-03 14:42:28 +00:00
|
|
|
// these tags are reserved by dioxus for any reason
|
|
|
|
// They might not all be used
|
|
|
|
static RESERVED_TAGS: Lazy<HashSet<&'static str>> = Lazy::new(|| {
|
|
|
|
[
|
|
|
|
// a fragment
|
|
|
|
"fragment",
|
|
|
|
]
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
|
|
|
.collect()
|
|
|
|
});
|
|
|
|
|
2021-03-08 02:28:20 +00:00
|
|
|
/// Whether or not this tag is valid
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// use html_validation::is_valid_tag;
|
|
|
|
///
|
|
|
|
/// assert_eq!(is_valid_tag("br"), true);
|
|
|
|
///
|
|
|
|
/// assert_eq!(is_valid_tag("random"), false);
|
|
|
|
/// ```
|
2021-05-31 22:55:56 +00:00
|
|
|
pub fn is_valid_tag(tag: &str) -> bool {
|
2021-06-03 14:42:28 +00:00
|
|
|
is_valid_html_tag(tag) || is_valid_svg_tag(tag) || is_valid_reserved_tag(tag)
|
2021-05-31 22:55:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 16:03:08 +00:00
|
|
|
pub fn is_valid_html_tag(tag: &str) -> bool {
|
2021-05-31 22:55:56 +00:00
|
|
|
HTML_TAGS.contains(tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_valid_svg_tag(tag: &str) -> bool {
|
|
|
|
SVG_TAGS.contains(tag)
|
2021-03-08 02:28:20 +00:00
|
|
|
}
|
2021-06-03 14:42:28 +00:00
|
|
|
|
|
|
|
pub fn is_valid_reserved_tag(tag: &str) -> bool {
|
|
|
|
RESERVED_TAGS.contains(tag)
|
|
|
|
}
|