diff options
author | Rob Austein <sra@hactrn.net> | 2021-02-16 01:41:04 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2021-02-16 01:41:04 +0000 |
commit | 6c097fdeb067cbd14fbea438d3be0a6aff30fc59 (patch) | |
tree | 0f887bf112c1b2b9be93c193d8def7bf3499e5a0 | |
parent | 86202308b68db7a6cf299c5fe3cdee4dc1850330 (diff) |
Simplify convert_image()
-rwxr-xr-x | trac2md.py | 19 |
1 files changed, 7 insertions, 12 deletions
@@ -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 |