Blob Blame History Raw
From 8ed43b1f9581fd81a29cb2902baf92a80d19bfb8 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Wed, 12 Dec 2018 14:50:48 +0100
Subject: [PATCH] Port pagure to markdown 3.0+ while remaining backward
 compatible

Lift the restriction in the requirements.txt

Fixes https://pagure.io/pagure/issue/3668

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
---
 pagure/pfmarkdown.py | 26 ++++++++++++++++++++++----
 requirements.txt     |  2 +-
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/pagure/pfmarkdown.py b/pagure/pfmarkdown.py
index 39820ab2..6e5355d9 100644
--- a/pagure/pfmarkdown.py
+++ b/pagure/pfmarkdown.py
@@ -34,6 +34,16 @@ import pagure.lib.query
 from pagure.config import config as pagure_config
 
 
+try:
+    from markdown.inlinepatterns import ImagePattern as ImagePattern
+
+    MK_VERSION = 2
+except ImportError:
+    from markdown.inlinepatterns import ImageInlineProcessor as ImagePattern
+
+    MK_VERSION = 3
+
+
 # the (?<!\w) (and variants) we use a lot in all these regexes is a
 # negative lookbehind assertion. It means 'match when the preceding
 # character is not in the \w class'. This stops us from starting a
@@ -325,11 +335,15 @@ class AutolinkPattern2(markdown.inlinepatterns.Pattern):
         return el
 
 
-class ImagePatternLazyLoad(markdown.inlinepatterns.ImagePattern):
+class ImagePatternLazyLoad(ImagePattern):
     """ Customize the image element matched for lazyloading. """
 
-    def handleMatch(self, m):
-        el = super(ImagePatternLazyLoad, self).handleMatch(m)
+    def handleMatch(self, m, *args):
+        out = super(ImagePatternLazyLoad, self).handleMatch(m, *args)
+        if MK_VERSION == 3:
+            el = out[0]
+        else:
+            el = out
 
         # Add a noscript tag with the untouched img tag
         noscript = markdown.util.etree.Element("noscript")
@@ -348,7 +362,11 @@ class ImagePatternLazyLoad(markdown.inlinepatterns.ImagePattern):
         outel.append(img)
         outel.append(noscript)
 
-        return outel
+        output = outel
+        if MK_VERSION == 3:
+            output = (outel, out[1], out[2])
+
+        return output
 
 
 class PagureExtension(markdown.extensions.Extension):
diff --git a/requirements.txt b/requirements.txt
index 95dab43e..15475f68 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -14,7 +14,7 @@ enum34;python_version<"3.4"
 flask
 flask-wtf
 kitchen
-markdown < 3.0
+markdown
 munch
 Pillow
 psutil
-- 
2.17.2