From 6c097fdeb067cbd14fbea438d3be0a6aff30fc59 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 16 Feb 2021 01:41:04 +0000 Subject: Simplify convert_image() --- trac2md.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'trac2md.py') diff --git a/trac2md.py b/trac2md.py index cf8ecdf..4453b09 100755 --- a/trac2md.py +++ b/trac2md.py @@ -91,18 +91,13 @@ def convert_wikilinks(line, slug, giturl): def convert_image(line, slug): - image_result = image_pattern.search(line) - if image_result: - try: - image_text = image_result.group(1).split(",")[0].strip() - old_text = image_result.group(0) - if "://" in image_text: - new_text = "".format(image_text) - else: - new_text = "![{}]({{attach}}{}/{})".format(image_text, slug, quote(image_text, "")) - line = line.replace(old_text, new_text) - except: - pass + for m in image_pattern.finditer(line): + text = m.group(1).split(",")[0].strip() + if "://" in text: + mdlink = "".format(text) + else: + mdlink = "![{}]({{attach}}{}/{})".format(text, slug, quote(text, "")) + line = line.replace(m.group(0), mdlink) return line -- cgit v1.2.3