[Cryptech-Commits] [user/sra/pelican] 54/68: Simplify convert_image()

git at cryptech.is git at cryptech.is
Mon Jul 19 22:25:33 UTC 2021


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch pelican
in repository user/sra/pelican.

commit 6c097fdeb067cbd14fbea438d3be0a6aff30fc59
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue Feb 16 01:41:04 2021 +0000

    Simplify convert_image()
---
 trac2md.py | 19 +++++++------------
 1 file 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
 
 



More information about the Commits mailing list