-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
While the defaults will work for most people, some may want raw (or another variant) to be the default. This is currently possible by creating a new escaper group that calls the existing public functions, but it's pretty verbose, although it only has to be done once per project:
use oxiplate::escapers::html::{escape_text, escape_attribute_quoted_value, escape_comment_text};
pub enum CustomHtmlEscaper {
/// Escaper for [text](https://html.spec.whatwg.org/#text-content) in an HTML document.
/// See [`escape_text()`] for details.
Text,
/// Escaper for single- and double-quoted [attribute values](https://html.spec.whatwg.org/#syntax-attribute-value) in an HTML document.
/// See [`escape_attribute_quoted_value()`] for details.
Attr,
/// Escaper for [comment text](https://html.spec.whatwg.org/#comments) in an HTML document.
/// See [`escape_comment_text()`] for details.
Comment,
/// Do not escape anything using this.
Raw,
}
impl super::Escaper for CustomHtmlEscaper {
const DEFAULT: Self = Self::Raw;
fn escape<'a>(&self, value: &'a str) -> Cow<'a, str> {
match self {
Self::Text => escape_text(value),
Self::Attr => escape_attribute_quoted_value(value),
Self::Comment => escape_comment_text(value),
Self::Raw => value,
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request