1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SectioningType {
    // ----- Sectioning Content -----
    Article,
    Aside,
    Nav,
    Section,

    // ----- Element -----
    Root,
    Body,
    Heading,
}

impl SectioningType {
    #[inline]
    pub(crate) fn is_sectioning_content_type(&self) -> bool {
        match self {
            SectioningType::Article
            | SectioningType::Aside
            | SectioningType::Nav
            | SectioningType::Section => true,
            _ => false,
        }
    }

    #[inline]
    pub(crate) fn is_heading(&self) -> bool {
        if let SectioningType::Heading = self {
            true
        } else {
            false
        }
    }

    #[inline]
    pub fn from_sectioning_content_tag<S: AsRef<str>>(s: S) -> Option<SectioningType> {
        let s = s.as_ref();

        match s {
            "article" => Some(SectioningType::Article),
            "aside" => Some(SectioningType::Aside),
            "nav" => Some(SectioningType::Nav),
            "section" => Some(SectioningType::Section),
            _ => None,
        }
    }

    #[inline]
    pub fn as_str(&self) -> &'static str {
        match self {
            SectioningType::Article => "article",
            SectioningType::Aside => "aside",
            SectioningType::Nav => "nav",
            SectioningType::Section => "section",
            SectioningType::Root => "root",
            SectioningType::Body => "body",
            SectioningType::Heading => "heading",
        }
    }
}