#[non_exhaustive]pub enum HtmlContext {
Unescaped,
Text,
AttributeValue,
Comment,
AttributeKey,
ElementName,
}Expand description
The position in an HTML document that a dynamic value is written into.
Writing through a context makes the value safe for that position. Contexts where HTML provides an escape mechanism rewrite the significant characters; ident contexts, where character references are never decoded, validate instead and panic on characters that could break out of the position:
| Context | & | < | > | " | Other |
|---|---|---|---|---|---|
Unescaped | - | - | - | - | - |
Text | & | < | > | - | - |
AttributeValue | & | - | - | " | - |
Comment | & | - | > | " | - |
AttributeKey | - | panic | panic | panic | see below |
ElementName | - | panic | panic | panic | see below |
The ident contexts reject ASCII whitespace, ASCII control characters,
", ', <, >, /, and =: the characters the HTML tokenizer can
treat as ending or altering a name token. This guarantees the identifier
cannot terminate or corrupt its token; it does not check full spec
validity.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Unescaped
Trusted markup written verbatim.
Text
A text node between tags. Quotes are not significant here, so the three escapable characters are found with a single search.
AttributeValue
A double-quoted attribute value. Only & and " can terminate or
alter the value, found with a single search.
Comment
A machine-readable payload inside an HTML comment, such as the markers
the interactive runtime emits. Escaping > guarantees the payload
cannot contain --> and terminate the comment, while & and "
round-trip through entity decoding so double-quoted strings inside the
payload stay unambiguous. Comment data is never entity-decoded by the
browser, so the consumer of the payload must decode it.
AttributeKey
An attribute name, validated as an identifier rather than escaped.
ElementName
A tag name, validated as an identifier rather than escaped.
Implementations§
Source§impl HtmlContext
impl HtmlContext
Sourcepub fn writer<'a, 'b>(self, f: &'a mut Formatter<'b>) -> HtmlWriter<'a, 'b>
pub fn writer<'a, 'b>(self, f: &'a mut Formatter<'b>) -> HtmlWriter<'a, 'b>
Returns a writer that makes everything written to it safe for this
context before appending it to f.
Trait Implementations§
Source§impl Clone for HtmlContext
impl Clone for HtmlContext
Source§fn clone(&self) -> HtmlContext
fn clone(&self) -> HtmlContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for HtmlContext
Source§impl Debug for HtmlContext
impl Debug for HtmlContext
impl Eq for HtmlContext
Source§impl PartialEq for HtmlContext
impl PartialEq for HtmlContext
impl StructuralPartialEq for HtmlContext
Auto Trait Implementations§
impl Freeze for HtmlContext
impl RefUnwindSafe for HtmlContext
impl Send for HtmlContext
impl Sync for HtmlContext
impl Unpin for HtmlContext
impl UnsafeUnpin for HtmlContext
impl UnwindSafe for HtmlContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.