pub fn unescape_in<'a, S: Into<Cow<'a, str>>>(
escaped: S,
context: Context,
) -> Cow<'a, str>
Available on crate features
unescape
or unescape_fast
only.Expand description
Expand all valid entities in a given context.
context
may be:
Context::General
: use the rules for text outside of an attribute. This is usually what you want.Context::Attribute
: use the rules for attribute values.
This uses the algorithm described in the WHATWG spec. In attributes,
named entities without trailing semicolons are treated differently. They
not expanded if they are followed by an alphanumeric character or or =
.
For example:
use htmlize::*;
assert!(unescape_in("×", Context::General) == "×");
assert!(unescape_in("×", Context::Attribute) == "×");
assert!(unescape_in("×X", Context::General) == "×X");
assert!(unescape_in("×X", Context::Attribute) == "×X");
assert!(unescape_in("×X", Context::General) == "×X");
assert!(unescape_in("×X", Context::Attribute) == "×X");
assert!(unescape_in("×=", Context::General) == "×=");
assert!(unescape_in("×=", Context::Attribute) == "×=");
assert!(unescape_in("×#", Context::General) == "×#");
assert!(unescape_in("×#", Context::Attribute) == "×#");
To work with bytes ([u8]
) instead of strings, see unescape_bytes_in()
.