summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2021-02-16 01:41:04 +0000
committerRob Austein <sra@hactrn.net>2021-02-16 01:41:04 +0000
commit6c097fdeb067cbd14fbea438d3be0a6aff30fc59 (patch)
tree0f887bf112c1b2b9be93c193d8def7bf3499e5a0
parent86202308b68db7a6cf299c5fe3cdee4dc1850330 (diff)
Simplify convert_image()
-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