use html5ever::{QualName, ns};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[repr(u8)]
pub(crate) enum Tag {
A,
Abbr,
Address,
Article,
Aside,
Audio,
B,
Bdi,
Bdo,
Blockquote,
Body,
Br,
Button,
Canvas,
Caption,
Cite,
Code,
Col,
Colgroup,
Data,
Datalist,
Dd,
Del,
Details,
Dfn,
Div,
Dl,
Dt,
Em,
Embed,
Fieldset,
Figcaption,
Figure,
Font,
Footer,
Form,
H1,
H2,
H3,
H4,
H5,
H6,
Head,
Header,
Hr,
Html,
I,
Iframe,
Img,
Input,
Ins,
Kbd,
Label,
Li,
Link,
Main,
Mark,
Math,
Meta,
Meter,
Nav,
Noscript,
Object,
Ol,
Option,
Output,
P,
Picture,
Pre,
Progress,
Q,
Ruby,
Samp,
Script,
Section,
Select,
Small,
Source,
Span,
Strong,
Style,
Sub,
Summary,
Sup,
Svg,
Table,
Tbody,
Td,
Template,
Textarea,
Tfoot,
Th,
Thead,
Time,
Title,
Tr,
U,
Ul,
Var,
Video,
Wbr,
Other,
}
impl Tag {
pub(crate) fn from_qual_name(name: &QualName) -> Self {
if name.ns == ns!(svg) {
Self::Svg
} else if name.ns == ns!(mathml) {
Self::Math
} else if name.ns != ns!(html) {
Self::Other
} else {
Self::from_local(name.local.as_ref())
}
}
pub(crate) fn from_local(name: &str) -> Self {
let lowercase;
let name = if name.bytes().any(|byte| byte.is_ascii_uppercase()) {
lowercase = name.to_ascii_lowercase();
lowercase.as_str()
} else {
name
};
match name {
"a" => Self::A,
"abbr" => Self::Abbr,
"address" => Self::Address,
"article" => Self::Article,
"aside" => Self::Aside,
"audio" => Self::Audio,
"b" => Self::B,
"bdi" => Self::Bdi,
"bdo" => Self::Bdo,
"blockquote" => Self::Blockquote,
"body" => Self::Body,
"br" => Self::Br,
"button" => Self::Button,
"canvas" => Self::Canvas,
"caption" => Self::Caption,
"cite" => Self::Cite,
"code" => Self::Code,
"col" => Self::Col,
"colgroup" => Self::Colgroup,
"data" => Self::Data,
"datalist" => Self::Datalist,
"dd" => Self::Dd,
"del" => Self::Del,
"details" => Self::Details,
"dfn" => Self::Dfn,
"div" => Self::Div,
"dl" => Self::Dl,
"dt" => Self::Dt,
"em" => Self::Em,
"embed" => Self::Embed,
"fieldset" => Self::Fieldset,
"figcaption" => Self::Figcaption,
"figure" => Self::Figure,
"font" => Self::Font,
"footer" => Self::Footer,
"form" => Self::Form,
"h1" => Self::H1,
"h2" => Self::H2,
"h3" => Self::H3,
"h4" => Self::H4,
"h5" => Self::H5,
"h6" => Self::H6,
"head" => Self::Head,
"header" => Self::Header,
"hr" => Self::Hr,
"html" => Self::Html,
"i" => Self::I,
"iframe" => Self::Iframe,
"img" => Self::Img,
"input" => Self::Input,
"ins" => Self::Ins,
"kbd" => Self::Kbd,
"label" => Self::Label,
"li" => Self::Li,
"link" => Self::Link,
"main" => Self::Main,
"mark" => Self::Mark,
"math" => Self::Math,
"meta" => Self::Meta,
"meter" => Self::Meter,
"nav" => Self::Nav,
"noscript" => Self::Noscript,
"object" => Self::Object,
"ol" => Self::Ol,
"option" => Self::Option,
"output" => Self::Output,
"p" => Self::P,
"picture" => Self::Picture,
"pre" => Self::Pre,
"progress" => Self::Progress,
"q" => Self::Q,
"ruby" => Self::Ruby,
"samp" => Self::Samp,
"script" => Self::Script,
"section" => Self::Section,
"select" => Self::Select,
"small" => Self::Small,
"source" => Self::Source,
"span" => Self::Span,
"strong" => Self::Strong,
"style" => Self::Style,
"sub" => Self::Sub,
"summary" => Self::Summary,
"sup" => Self::Sup,
"svg" => Self::Svg,
"table" => Self::Table,
"tbody" => Self::Tbody,
"td" => Self::Td,
"template" => Self::Template,
"textarea" => Self::Textarea,
"tfoot" => Self::Tfoot,
"th" => Self::Th,
"thead" => Self::Thead,
"time" => Self::Time,
"title" => Self::Title,
"tr" => Self::Tr,
"u" => Self::U,
"ul" => Self::Ul,
"var" => Self::Var,
"video" => Self::Video,
"wbr" => Self::Wbr,
_ => Self::Other,
}
}
pub(crate) const fn as_lowercase_str(self) -> &'static str {
match self {
Self::A => "a",
Self::Abbr => "abbr",
Self::Address => "address",
Self::Article => "article",
Self::Aside => "aside",
Self::Audio => "audio",
Self::B => "b",
Self::Bdi => "bdi",
Self::Bdo => "bdo",
Self::Blockquote => "blockquote",
Self::Body => "body",
Self::Br => "br",
Self::Button => "button",
Self::Canvas => "canvas",
Self::Caption => "caption",
Self::Cite => "cite",
Self::Code => "code",
Self::Col => "col",
Self::Colgroup => "colgroup",
Self::Data => "data",
Self::Datalist => "datalist",
Self::Dd => "dd",
Self::Del => "del",
Self::Details => "details",
Self::Dfn => "dfn",
Self::Div => "div",
Self::Dl => "dl",
Self::Dt => "dt",
Self::Em => "em",
Self::Embed => "embed",
Self::Fieldset => "fieldset",
Self::Figcaption => "figcaption",
Self::Figure => "figure",
Self::Font => "font",
Self::Footer => "footer",
Self::Form => "form",
Self::H1 => "h1",
Self::H2 => "h2",
Self::H3 => "h3",
Self::H4 => "h4",
Self::H5 => "h5",
Self::H6 => "h6",
Self::Head => "head",
Self::Header => "header",
Self::Hr => "hr",
Self::Html => "html",
Self::I => "i",
Self::Iframe => "iframe",
Self::Img => "img",
Self::Input => "input",
Self::Ins => "ins",
Self::Kbd => "kbd",
Self::Label => "label",
Self::Li => "li",
Self::Link => "link",
Self::Main => "main",
Self::Mark => "mark",
Self::Math => "math",
Self::Meta => "meta",
Self::Meter => "meter",
Self::Nav => "nav",
Self::Noscript => "noscript",
Self::Object => "object",
Self::Ol => "ol",
Self::Option => "option",
Self::Output => "output",
Self::P => "p",
Self::Picture => "picture",
Self::Pre => "pre",
Self::Progress => "progress",
Self::Q => "q",
Self::Ruby => "ruby",
Self::Samp => "samp",
Self::Script => "script",
Self::Section => "section",
Self::Select => "select",
Self::Small => "small",
Self::Source => "source",
Self::Span => "span",
Self::Strong => "strong",
Self::Style => "style",
Self::Sub => "sub",
Self::Summary => "summary",
Self::Sup => "sup",
Self::Svg => "svg",
Self::Table => "table",
Self::Tbody => "tbody",
Self::Td => "td",
Self::Template => "template",
Self::Textarea => "textarea",
Self::Tfoot => "tfoot",
Self::Th => "th",
Self::Thead => "thead",
Self::Time => "time",
Self::Title => "title",
Self::Tr => "tr",
Self::U => "u",
Self::Ul => "ul",
Self::Var => "var",
Self::Video => "video",
Self::Wbr => "wbr",
Self::Other => "",
}
}
}