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

Function normalizeLinkText

markdown_it/common/normalize_url.py:40–63  ·  view source on GitHub ↗

Normalize autolink content :: ~~~~~~~~~~~

(url: str)

Source from the content-addressed store, hash-verified

38
39
40def 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
66BAD_PROTO_RE = re.compile(r"^(vbscript|javascript|file|data):")

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…