use super::Node;
use ecow::EcoString;
#[derive(Debug, Clone, PartialEq)]
pub struct HtmlAttribute {
pub name: EcoString,
pub value: EcoString,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HtmlElement {
pub tag: EcoString,
pub attributes: Vec<HtmlAttribute>,
pub children: Vec<Node>,
pub self_closing: bool,
}
impl HtmlElement {
pub fn new(tag: &str) -> Self {
Self {
tag: tag.into(),
attributes: Vec::new(),
children: Vec::new(),
self_closing: false,
}
}
pub fn with_attribute(mut self, name: &str, value: &str) -> Self {
self.attributes.push(HtmlAttribute {
name: name.into(),
value: value.into(),
});
self
}
pub fn with_attributes(mut self, attrs: Vec<(&str, &str)>) -> Self {
for (name, value) in attrs {
self.attributes.push(HtmlAttribute {
name: name.into(),
value: value.into(),
});
}
self
}
pub fn with_children(mut self, children: Vec<Node>) -> Self {
self.children = children;
self
}
pub fn self_closing(mut self, is_self_closing: bool) -> Self {
self.self_closing = is_self_closing;
self
}
pub fn tag_matches_any(&self, tags: &[EcoString]) -> bool {
tags.iter().any(|tag| tag.eq_ignore_ascii_case(&self.tag))
}
}