hints kitten: Detect bracketed URLs and dont include the closing bracket in the URL.

This commit is contained in:
Kovid Goyal 2018-04-25 14:33:37 +05:30
parent b3ed4e3bc2
commit 61a2360df5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -158,6 +158,9 @@ def regex_finditer(pat, minimum_match_length, line):
yield s, e
closing_bracket_map = {'(': ')', '[': ']', '{': '}', '<': '>'}
def find_urls(pat, line):
for m in pat.finditer(line):
s, e = m.span()
@ -168,6 +171,9 @@ def find_urls(pat, line):
e -= len(url) - idx
while line[e - 1] in '.,?!' and e > 1: # remove trailing punctuation
e -= 1
# Detect a bracketed URL
if s > 0 and e > s + 4 and line[s-1] in '({[<' and line[e-1] == closing_bracket_map[line[s-1]]:
e -= 1
yield s, e