]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Post-process images to format them nicely
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Jul 2019 15:38:55 +0000 (16:38 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Jul 2019 15:38:55 +0000 (16:38 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/wiki.py

index 4601be4c14efc694cb808c7c2be62509bf2d56cb..5c4d0499cb713b19e7e4108b66675fb92e537b3c 100644 (file)
@@ -505,7 +505,7 @@ class WikiRenderer(misc.Object):
        email_link = re.compile(r"\[\[([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)(?:\|(.+?))?\]\]")
 
        # Images
-       images = re.compile(r"{{([\w\d\/\-\.]+)(?:\|(.+?))?}}")
+       images = re.compile(r"<img src=\"(.*?)\" alt=\"(.*?)\" (?:title=\"(.*?)\" )?/>")
 
        def init(self, path):
                self.path = path
@@ -569,13 +569,13 @@ class WikiRenderer(misc.Object):
                        % (address, alias or address)
 
        def _render_image(self, m):
-               url, caption = m.groups()
+               url, alt_text, caption = m.groups()
 
                # Skip any absolute and external URLs
                if url.startswith("/") or url.startswith("https://") or url.startswith("http://"):
                        return """<figure class="figure"><img src="%s" class="figure-img img-fluid rounded" alt="%s">
                                <figcaption class="figure-caption">%s</figcaption></figure>
-                       """ % (url, url, caption or "")
+                       """ % (url, alt_text, caption or "")
 
                # Try to split query string
                url, delimiter, qs = url.partition("?")
@@ -614,8 +614,10 @@ class WikiRenderer(misc.Object):
                # Handle email links
                text = self.email_link.sub(self._render_email_link, text)
 
-               # Handle images
+               # Borrow this from the blog
+               text = self.backend.blog._render_text(text, lang="markdown")
+
+               # Postprocess images to <figure>
                text = self.images.sub(self._render_image, text)
 
-               # Borrow this from the blog
-               return self.backend.blog._render_text(text, lang="markdown")
+               return text