Normalize destination URLs in links :: [label]: destination 'title' ^^^^^^^^^^^
(url: str)
| 13 | |
| 14 | |
| 15 | def normalizeLink(url: str) -> str: |
| 16 | """Normalize destination URLs in links |
| 17 | |
| 18 | :: |
| 19 | |
| 20 | [label]: destination 'title' |
| 21 | ^^^^^^^^^^^ |
| 22 | """ |
| 23 | parsed = mdurl.parse(url, slashes_denote_host=True) |
| 24 | |
| 25 | # Encode hostnames in urls like: |
| 26 | # `http://host/`, `https://host/`, `mailto:user@host`, `//host/` |
| 27 | # |
| 28 | # We don't encode unknown schemas, because it's likely that we encode |
| 29 | # something we shouldn't (e.g. `skype:name` treated as `skype:host`) |
| 30 | # |
| 31 | if parsed.hostname and ( |
| 32 | not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR |
| 33 | ): |
| 34 | with suppress(Exception): |
| 35 | parsed = parsed._replace(hostname=_punycode.to_ascii(parsed.hostname)) |
| 36 | |
| 37 | return mdurl.encode(mdurl.format(parsed)) |
| 38 | |
| 39 | |
| 40 | def normalizeLinkText(url: str) -> str: |
nothing calls this directly
no test coverage detected
searching dependent graphs…