use html5ever::{local_name, namespace_url, ns, tendril::StrTendril, QualName};
use std::collections::{btree_map::Entry, BTreeMap};
#[derive(Debug)]
pub(crate) struct Attributes {
pub(crate) map: BTreeMap<QualName, StrTendril>,
}
pub(crate) const CSS_INLINE_ATTRIBUTE: &str = "data-css-inline";
pub(super) fn should_ignore(attributes: &[html5ever::Attribute]) -> bool {
attributes
.iter()
.any(|a| a.name.local == *CSS_INLINE_ATTRIBUTE && a.value == "ignore".into())
}
impl Attributes {
pub(crate) fn new(attributes: Vec<html5ever::Attribute>) -> Attributes {
Attributes {
map: attributes
.into_iter()
.map(|attr| (attr.name, attr.value))
.collect(),
}
}
pub(crate) fn contains(&self, local: html5ever::LocalName) -> bool {
self.map.contains_key(&QualName::new(None, ns!(), local))
}
pub(crate) fn get(&self, local: html5ever::LocalName) -> Option<&str> {
self.map
.get(&QualName::new(None, ns!(), local))
.map(|value| &**value)
}
pub(crate) fn get_style_entry(&mut self) -> Entry<'_, QualName, StrTendril> {
self.map
.entry(QualName::new(None, ns!(), local_name!("style")))
}
}