aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtrac2md.py19
1 files changed, 7 insertions, 12 deletions
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 = "<img src=\"{}\">".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 = "<img src=\"{}\">".format(text)
+ else:
+ mdlink = "![{}]({{attach}}{}/{})".format(text, slug, quote(text, ""))
+ line = line.replace(m.group(0), mdlink)
return line