MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / normalizeLink

Function normalizeLink

markdown_it/common/normalize_url.py:15–37  ·  view source on GitHub ↗

Normalize destination URLs in links :: [label]: destination 'title' ^^^^^^^^^^^

(url: str)

Source from the content-addressed store, hash-verified

13
14
15def 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
40def normalizeLinkText(url: str) -> str:

Callers

nothing calls this directly

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…