Normalize autolink content :: ~~~~~~~~~~~
(url: str)
| 38 | |
| 39 | |
| 40 | def normalizeLinkText(url: str) -> str: |
| 41 | """Normalize autolink content |
| 42 | |
| 43 | :: |
| 44 | |
| 45 | <destination> |
| 46 | ~~~~~~~~~~~ |
| 47 | """ |
| 48 | parsed = mdurl.parse(url, slashes_denote_host=True) |
| 49 | |
| 50 | # Encode hostnames in urls like: |
| 51 | # `http://host/`, `https://host/`, `mailto:user@host`, `//host/` |
| 52 | # |
| 53 | # We don't encode unknown schemas, because it's likely that we encode |
| 54 | # something we shouldn't (e.g. `skype:name` treated as `skype:host`) |
| 55 | # |
| 56 | if parsed.hostname and ( |
| 57 | not parsed.protocol or parsed.protocol in RECODE_HOSTNAME_FOR |
| 58 | ): |
| 59 | with suppress(Exception): |
| 60 | parsed = parsed._replace(hostname=_punycode.to_unicode(parsed.hostname)) |
| 61 | |
| 62 | # add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720 |
| 63 | return mdurl.decode(mdurl.format(parsed), mdurl.DECODE_DEFAULT_CHARS + "%") |
| 64 | |
| 65 | |
| 66 | BAD_PROTO_RE = re.compile(r"^(vbscript|javascript|file|data):") |
nothing calls this directly
no test coverage detected
searching dependent graphs…