@@ -60,14 +60,32 @@ def normalize_uri(uri):
6060RECODE_HOSTNAME_FOR = ("http" , "https" , "mailto" )
6161
6262
63+ def unescape_normalize_uri (x ):
64+ return normalize_uri (unescape_string (x ))
65+
66+
6367def normalizeLink (url ):
6468 """Normalize destination URLs in links::
6569
6670 [label]: destination 'title'
6771 ^^^^^^^^^^^
6872 """
69- url_unescaped = unescape_string (url )
70- return normalize_uri (url_unescaped )
73+ (scheme , netloc , path , params , query , fragment ) = urlparse (url )
74+ if scheme in RECODE_HOSTNAME_FOR :
75+ url = urlunparse (
76+ (
77+ scheme ,
78+ unescape_normalize_uri (netloc ),
79+ unescape_normalize_uri (path ),
80+ unescape_normalize_uri (params ),
81+ normalize_uri (query ),
82+ unescape_normalize_uri (fragment ),
83+ )
84+ )
85+ else :
86+ url = unescape_normalize_uri (url )
87+
88+ return url
7189
7290 # TODO the selective encoding below should probably be done here,
7391 # something like:
@@ -90,13 +108,31 @@ def normalizeLink(url):
90108 # return quote(urlunparse(parsed))
91109
92110
111+ def unescape_unquote (x ):
112+ return unquote (unescape_string (x ))
113+
114+
93115def normalizeLinkText (title ):
94116 """Normalize autolink content::
95117
96118 <destination>
97119 ~~~~~~~~~~~
98120 """
99- return unquote (unescape_string (title ))
121+ (scheme , netloc , path , params , query , fragment ) = urlparse (title )
122+ if scheme in RECODE_HOSTNAME_FOR :
123+ url = urlunparse (
124+ (
125+ scheme ,
126+ unescape_unquote (netloc ),
127+ unquote (path ),
128+ unescape_unquote (params ),
129+ unquote (query ),
130+ unescape_unquote (fragment ),
131+ )
132+ )
133+ else :
134+ url = unescape_unquote (title )
135+ return url
100136
101137 # TODO the selective encoding below should probably be done here,
102138 # something like:
0 commit comments