Function escape_href
pub fn escape_href(output: &mut dyn Write, buffer: &str, relaxed_ipv6: bool) -> Result
Writes buffer to output, escaping in a manner appropriate for URLs in HTML attributes.
Namely:
- U+0026 AMPERSAND & is rendered as &
- U+0027 APOSTROPHE ' is rendered as '
- Alphanumeric and a range of non-URL safe characters.
Note that we leave "%" alone if it is followed by two hexdigits. See:
In other words, if a CommonMark user enters:
We assume they actually want the query string "?q=a%20b", a search for the string "a b", rather than "?q=a%2520b", a search for the literal string "a%20b".
We take some care with the square bracket characters [ and ]. We permit
them to be unescaped in the output iff they surround what reasonably appears
to be an IPv6 address in the host part of a URI. If relaxed_ipv6 is
true, any scheme is permitted for such an address. Otherwise, only http
or https are permitted.