maud
maud copied to clipboard
Redesign `PreEscaped` API
The current PreEscaped API has a few issues:
- The
PreEscaped/Markupnaming was lifted fromblaze-markup, which supports both HTML and XML. But Maud was always HTML-only, and the upcoming context-aware escaping effort will deepen this specialization.- Let's rename it to just
Html.
- Let's rename it to just
PreEscapedwraps anyT: AsRef<str>, but I've only seen it used withStringand&'static str.- Let's make it wrap
Cow<'static, str>instead.
- Let's make it wrap
- The
PreEscapedconstructor makes it too easy to treat any arbitrary string as HTML. Modern APIs like the Trusted Types proposal force the user to do some sanitizing/escaping first, or at least acknowledge the security risk if they don't.- Let's remove the public constructor, and replace it with...
Notice how the safe (impl Html { pub sanitize(value: &str) -> Self; pub from_trusted(value: impl Into<Cow<'static, str>>) -> Self; }sanitize) option is shorter!
- Let's remove the public constructor, and replace it with...
Just wanted to mention that PreEscaped was confusing to me when I discovered maud. So :+1: on that rename, it would be a net positive wrt discoverability, IMO.
There needs to be consideration for making sure it is possible to serialize Html for use-cases like pushing DOM updates over websocket messages. Either Html need to be Into<String> or maud needs to have a serde feature.