@@ -60,14 +60,32 @@ def normalize_uri(uri):
60
60
RECODE_HOSTNAME_FOR = ("http" , "https" , "mailto" )
61
61
62
62
63
+ def unescape_normalize_uri (x ):
64
+ return normalize_uri (unescape_string (x ))
65
+
66
+
63
67
def normalizeLink (url ):
64
68
"""Normalize destination URLs in links::
65
69
66
70
[label]: destination 'title'
67
71
^^^^^^^^^^^
68
72
"""
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
71
89
72
90
# TODO the selective encoding below should probably be done here,
73
91
# something like:
@@ -90,13 +108,31 @@ def normalizeLink(url):
90
108
# return quote(urlunparse(parsed))
91
109
92
110
111
+ def unescape_unquote (x ):
112
+ return unquote (unescape_string (x ))
113
+
114
+
93
115
def normalizeLinkText (title ):
94
116
"""Normalize autolink content::
95
117
96
118
<destination>
97
119
~~~~~~~~~~~
98
120
"""
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
100
136
101
137
# TODO the selective encoding below should probably be done here,
102
138
# something like:
0 commit comments