Browse Source

Better images handling in markdown.

Ralfp 12 years ago
parent
commit
43d0090bbb
2 changed files with 10 additions and 7 deletions
  1. 9 5
      misago/markdown/extensions/shorthandimgs.py
  2. 1 2
      static/cranefly/js/cranefly.js

+ 9 - 5
misago/markdown/extensions/shorthandimgs.py

@@ -20,9 +20,13 @@ class ShorthandImagePattern(LinkPattern):
     def handleMatch(self, m):
     def handleMatch(self, m):
         img_src = m.groups()[2].strip()
         img_src = m.groups()[2].strip()
         if is_inner(img_src):
         if is_inner(img_src):
-            img_src = clean_inner(img_src)
+            img_src = self.sanitize_url(clean_inner(img_src))
         if img_src:
         if img_src:
-            el = etree.Element("img")
-            el.set('alt', img_src)
-            el.set('src', img_src)
-            return el
+            a = etree.Element("a")
+            a.set('href', img_src)
+            a.set('rel', 'nofollow')
+            a.set('target', '_blank')
+            img = etree.SubElement(a, "img")
+            img.set('src', img_src)
+            img.set('alt', img_src)
+            return a

+ 1 - 2
static/cranefly/js/cranefly.js

@@ -78,9 +78,8 @@ function EnhancePostsMD() {
       $(this).addClass('img-rounded');
       $(this).addClass('img-rounded');
       if ($(this).attr('alt').length > 0 && $(this).attr('alt') != $(this).attr('src')) {
       if ($(this).attr('alt').length > 0 && $(this).attr('alt') != $(this).attr('src')) {
         $(this).attr('title', $(this).attr('alt'));
         $(this).attr('title', $(this).attr('alt'));
+        $(this).tooltip({placement: 'top', container: 'body'});
       }
       }
-      $(this).tooltip({placement: 'top', container: 'body'});
-      $(this).wrap('<a href="' + escape($(this).attr('src')) + '" target="_blank"/>');
     });
     });
 
 
     // Automagically turn links into players
     // Automagically turn links into players