1use super::Node;
7use ecow::EcoString;
8
9#[derive(Debug, Clone, PartialEq)]
11pub struct HtmlAttribute {
12 pub name: EcoString,
14 pub value: EcoString,
16}
17
18#[derive(Debug, Clone, PartialEq)]
20pub struct HtmlElement {
21 pub tag: EcoString,
23 pub attributes: Vec<HtmlAttribute>,
25 pub children: Vec<Node>,
27 pub self_closing: bool,
29}
30
31impl HtmlElement {
32 pub fn new(tag: &str) -> Self {
34 Self {
35 tag: tag.into(),
36 attributes: Vec::new(),
37 children: Vec::new(),
38 self_closing: false,
39 }
40 }
41
42 pub fn with_attribute(mut self, name: &str, value: &str) -> Self {
44 self.attributes.push(HtmlAttribute {
45 name: name.into(),
46 value: value.into(),
47 });
48 self
49 }
50
51 pub fn with_attributes(mut self, attrs: Vec<(&str, &str)>) -> Self {
53 for (name, value) in attrs {
54 self.attributes.push(HtmlAttribute {
55 name: name.into(),
56 value: value.into(),
57 });
58 }
59 self
60 }
61
62 pub fn with_children(mut self, children: Vec<Node>) -> Self {
64 self.children = children;
65 self
66 }
67
68 pub fn self_closing(mut self, is_self_closing: bool) -> Self {
70 self.self_closing = is_self_closing;
71 self
72 }
73
74 pub fn tag_matches_any(&self, tags: &[EcoString]) -> bool {
76 tags.iter().any(|tag| tag.eq_ignore_ascii_case(&self.tag))
77 }
78}