textlane-html 0.0.0

Textlane's HTML plugins: parsing, transforms, sanitizing and serializing
Documentation
/// A tag parse5 knows by id, the elements the tree builder treats specially.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum TagId {
    Unknown,
    A,
    Address,
    AnnotationXml,
    Applet,
    Area,
    Article,
    Aside,
    B,
    Base,
    Basefont,
    Bgsound,
    Big,
    Blockquote,
    Body,
    Br,
    Button,
    Caption,
    Center,
    Code,
    Col,
    Colgroup,
    Dd,
    Desc,
    Details,
    Dialog,
    Dir,
    Div,
    Dl,
    Dt,
    Em,
    Embed,
    Fieldset,
    Figcaption,
    Figure,
    Font,
    Footer,
    ForeignObject,
    Form,
    Frame,
    Frameset,
    H1,
    H2,
    H3,
    H4,
    H5,
    H6,
    Head,
    Header,
    Hgroup,
    Hr,
    Html,
    I,
    Img,
    Image,
    Input,
    Iframe,
    Keygen,
    Label,
    Li,
    Link,
    Listing,
    Main,
    Malignmark,
    Marquee,
    Math,
    Menu,
    Meta,
    Mglyph,
    Mi,
    Mo,
    Mn,
    Ms,
    Mtext,
    Nav,
    Nobr,
    Noframes,
    Noembed,
    Noscript,
    Object,
    Ol,
    Optgroup,
    Option,
    P,
    Param,
    Plaintext,
    Pre,
    Rb,
    Rp,
    Rt,
    Rtc,
    Ruby,
    S,
    Script,
    Search,
    Section,
    Select,
    Source,
    Small,
    Span,
    Strike,
    Strong,
    Style,
    Sub,
    Summary,
    Sup,
    Table,
    Tbody,
    Template,
    Textarea,
    Tfoot,
    Td,
    Th,
    Thead,
    Title,
    Tr,
    Track,
    Tt,
    U,
    Ul,
    Svg,
    Var,
    Wbr,
    Xmp,
}

// Sorted by name for a binary search
static TAG_IDS: [(&str, TagId); 123] = [
    ("a", TagId::A),
    ("address", TagId::Address),
    ("annotation-xml", TagId::AnnotationXml),
    ("applet", TagId::Applet),
    ("area", TagId::Area),
    ("article", TagId::Article),
    ("aside", TagId::Aside),
    ("b", TagId::B),
    ("base", TagId::Base),
    ("basefont", TagId::Basefont),
    ("bgsound", TagId::Bgsound),
    ("big", TagId::Big),
    ("blockquote", TagId::Blockquote),
    ("body", TagId::Body),
    ("br", TagId::Br),
    ("button", TagId::Button),
    ("caption", TagId::Caption),
    ("center", TagId::Center),
    ("code", TagId::Code),
    ("col", TagId::Col),
    ("colgroup", TagId::Colgroup),
    ("dd", TagId::Dd),
    ("desc", TagId::Desc),
    ("details", TagId::Details),
    ("dialog", TagId::Dialog),
    ("dir", TagId::Dir),
    ("div", TagId::Div),
    ("dl", TagId::Dl),
    ("dt", TagId::Dt),
    ("em", TagId::Em),
    ("embed", TagId::Embed),
    ("fieldset", TagId::Fieldset),
    ("figcaption", TagId::Figcaption),
    ("figure", TagId::Figure),
    ("font", TagId::Font),
    ("footer", TagId::Footer),
    ("foreignObject", TagId::ForeignObject),
    ("form", TagId::Form),
    ("frame", TagId::Frame),
    ("frameset", TagId::Frameset),
    ("h1", TagId::H1),
    ("h2", TagId::H2),
    ("h3", TagId::H3),
    ("h4", TagId::H4),
    ("h5", TagId::H5),
    ("h6", TagId::H6),
    ("head", TagId::Head),
    ("header", TagId::Header),
    ("hgroup", TagId::Hgroup),
    ("hr", TagId::Hr),
    ("html", TagId::Html),
    ("i", TagId::I),
    ("iframe", TagId::Iframe),
    ("image", TagId::Image),
    ("img", TagId::Img),
    ("input", TagId::Input),
    ("keygen", TagId::Keygen),
    ("label", TagId::Label),
    ("li", TagId::Li),
    ("link", TagId::Link),
    ("listing", TagId::Listing),
    ("main", TagId::Main),
    ("malignmark", TagId::Malignmark),
    ("marquee", TagId::Marquee),
    ("math", TagId::Math),
    ("menu", TagId::Menu),
    ("meta", TagId::Meta),
    ("mglyph", TagId::Mglyph),
    ("mi", TagId::Mi),
    ("mn", TagId::Mn),
    ("mo", TagId::Mo),
    ("ms", TagId::Ms),
    ("mtext", TagId::Mtext),
    ("nav", TagId::Nav),
    ("nobr", TagId::Nobr),
    ("noembed", TagId::Noembed),
    ("noframes", TagId::Noframes),
    ("noscript", TagId::Noscript),
    ("object", TagId::Object),
    ("ol", TagId::Ol),
    ("optgroup", TagId::Optgroup),
    ("option", TagId::Option),
    ("p", TagId::P),
    ("param", TagId::Param),
    ("plaintext", TagId::Plaintext),
    ("pre", TagId::Pre),
    ("rb", TagId::Rb),
    ("rp", TagId::Rp),
    ("rt", TagId::Rt),
    ("rtc", TagId::Rtc),
    ("ruby", TagId::Ruby),
    ("s", TagId::S),
    ("script", TagId::Script),
    ("search", TagId::Search),
    ("section", TagId::Section),
    ("select", TagId::Select),
    ("small", TagId::Small),
    ("source", TagId::Source),
    ("span", TagId::Span),
    ("strike", TagId::Strike),
    ("strong", TagId::Strong),
    ("style", TagId::Style),
    ("sub", TagId::Sub),
    ("summary", TagId::Summary),
    ("sup", TagId::Sup),
    ("svg", TagId::Svg),
    ("table", TagId::Table),
    ("tbody", TagId::Tbody),
    ("td", TagId::Td),
    ("template", TagId::Template),
    ("textarea", TagId::Textarea),
    ("tfoot", TagId::Tfoot),
    ("th", TagId::Th),
    ("thead", TagId::Thead),
    ("title", TagId::Title),
    ("tr", TagId::Tr),
    ("track", TagId::Track),
    ("tt", TagId::Tt),
    ("u", TagId::U),
    ("ul", TagId::Ul),
    ("var", TagId::Var),
    ("wbr", TagId::Wbr),
    ("xmp", TagId::Xmp),
];

/// The id of a tag name, as parse5's `getTagID`: exact, so `foreignobject` is unknown.
pub(crate) fn find_tag_id(name: &str) -> TagId {
    TAG_IDS
        .binary_search_by(|(each, _)| each.cmp(&name))
        .map_or(TagId::Unknown, |index| TAG_IDS[index].1)
}