use std::collections::HashSet;
#[derive(Debug, Clone)]
pub struct VoidTagOptions {
pub add_closing_slash: bool,
pub tags: Option<Vec<String>>, }
impl Default for VoidTagOptions {
fn default() -> Self {
Self {
add_closing_slash: false,
tags: None,
}
}
}
#[derive(Debug, Clone)]
pub struct VoidTag {
set: HashSet<String>, }
impl VoidTag {
pub fn new(opts: &VoidTagOptions) -> Self {
let base: Vec<String> = if let Some(custom) = &opts.tags {
custom.clone()
} else {
vec![
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta",
"param", "source", "track", "wbr",
]
.into_iter()
.map(|s| s.to_string())
.collect()
};
let mut set = HashSet::new();
for t in base.iter() {
set.insert(t.to_lowercase());
set.insert(t.to_uppercase());
}
Self {
set,
}
}
pub fn is_void(&self, tag: &str) -> bool {
self.set.contains(tag)
}
}