traitement des urls

This commit is contained in:
François Pelletier 2024-01-08 14:26:18 -05:00
parent 23314d8a53
commit 3317bb7de6

View file

@ -40,4 +40,9 @@ def replace_title_with_list(text: str) -> str:
if nb_hashtag > 1:
text = re.sub(match, ' ' * (nb_hashtag-1)+'-', text, count=1)
text = re.sub('\n\n', '\n', text)
pattern_url = \
r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
matches_url = re.findall(pattern_url, text, re.MULTILINE)
for match in matches_url:
text = text.replace(str(match[0]), f'[{str(match[0])}]({str(match[0])})')
return text