From 3317bb7de6485da44b2f4c450b752e5c7710ec8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Mon, 8 Jan 2024 14:26:18 -0500 Subject: [PATCH] traitement des urls --- markdown_fix_freeplane/markdown_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/markdown_fix_freeplane/markdown_utils.py b/markdown_fix_freeplane/markdown_utils.py index 8054f0c..de5d449 100644 --- a/markdown_fix_freeplane/markdown_utils.py +++ b/markdown_fix_freeplane/markdown_utils.py @@ -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