pub enum Mode {
Generic,
Html,
Xhtml,
}Expand description
The translator flavour: which pseudo-class overrides, name-casing
rules, and :lang() language source to apply.
Html and Xhtml share the HTML
pseudo-class overrides; only Html ASCII-lowercases element and
attribute names and folds HTML’s legacy case-insensitive attribute
values, and only Xhtml reads xml:lang.
Pseudo-classes with no static equivalent (:hover, :visited,
:focus, :dir(), …) translate to an unmatchable [0] in every
flavour, rather than erroring.
The enum is deliberately exhaustive: these three are the document
flavours CSS selector matching distinguishes, and callers benefit
more from exhaustive match than the crate would from room to add a
fourth.
Variants§
Generic
Plain CSS/XPath semantics: case-sensitive names, no
HTML-specific pseudo-classes, and :lang() via XPath’s own
lang() function.
This is the Default, as the flavour that assumes least about
the document.
Html
An HTML document, as an HTML parser leaves it: element and
attribute names are ASCII-lowercased, HTML’s legacy
case-insensitive attribute values (type, rel, …) compare
without regard to case, and :link, :checked,
:disabled/:enabled, :required/:optional and :lang()
take their static HTML meaning over the elements HTML defines
them for. :lang() reads the nearest @lang ancestor.
Xhtml
XHTML: the same HTML pseudo-class semantics as Mode::Html,
but case is preserved (XHTML is XML, so both names and those
attribute values are case-sensitive) and :lang() reads
xml:lang as well as lang, preferring xml:lang when both sit
on the nearest ancestor.
Implementations§
Trait Implementations§
impl Copy for Mode
impl Eq for Mode
Source§impl FromStr for Mode
impl FromStr for Mode
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse "generic", "html" or "xhtml", ignoring ASCII case, so
that a mode read from a CLI flag or a config file needs no
hand-written match in every caller.
Nothing else is accepted — not an abbreviation, not "xml" — and
the name is compared as-is, so surrounding whitespace is the
caller’s to trim.