When detecting URLs remove trailing "] and similar

This commit is contained in:
Kovid Goyal 2017-02-11 12:12:02 +05:30
parent 72125701f5
commit a671c7a184

View File

@ -374,6 +374,10 @@ class CharGrid:
for m in self.url_pat.finditer(text):
if m.start() <= x < m.end():
url = ''.join(l[i] for i in range(*m.span())).rstrip('.')
# Remove trailing "] and similar
url = re.sub(r'''["'][)}\]]$''', '', url)
# Remove closing trailing character if it is matched by it's
# corresponding opening character before the url
if m.start() > 0:
before = l[m.start() - 1]
closing = {'(': ')', '[': ']', '{': '}', '<': '>', '"': '"', "'": "'", '`': '`', '|': '|', ':': ':'}.get(before)