html_validation/self_closing.rs
1use lazy_static::lazy_static;
2use std::collections::hash_set::HashSet;
3
4use super::svg_namespace::is_self_closing_svg_tag;
5
6// Used to uniquely identify elements that contain closures so that the DomUpdater can
7// look them up by their unique id.
8// When the DomUpdater sees that the element no longer exists it will drop all of it's
9// Rc'd Closures for those events.
10lazy_static! {
11 static ref SELF_CLOSING_TAGS: HashSet<&'static str> = [
12 "area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "command",
13 "keygen", "source",
14 ]
15 .iter()
16 .cloned()
17 .collect();
18}
19
20/// Whether or not this tag is self closing
21///
22/// ```
23/// use html_validation::is_self_closing;
24///
25/// assert_eq!(is_self_closing("br"), true);
26///
27/// assert_eq!(is_self_closing("div"), false);
28/// ```
29pub fn is_self_closing(tag: &str) -> bool {
30 SELF_CLOSING_TAGS.contains(tag) || is_self_closing_svg_tag(tag)
31}