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:

Note that we leave "%" alone if it is followed by two hexdigits. See:

https://github.com/github/cmark-gfm/blob/c32ef78bae851cb83b7ad52d0fbff880acdcd44a/src/houdini_href_e.c#L7-L31

In other words, if a CommonMark user enters:

[hi]https://ddg.gg/?q=a%20b

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.