Commits

Christian Boos committed 2f81f30

0.12.3dev: better handling of InterTrac links in `[[Image()]]`

Make InterTrac links work in `Image()` macro when they have a "format=raw" attached.

Initial patch contributibuted by dstoecker on #10196.

Comments (0)

Files changed (2)

trac/wiki/formatter.py

                    escape(match)
 
     def _make_intertrac_link(self, ns, target, label):
+        res = self.get_intertrac_url(ns, target)
+        if res:
+            return self._make_ext_link(res[0], label, res[1])
+        else:
+            return None
+
+    def get_intertrac_url(self, ns, target):
         intertrac = self.env.config['intertrac']
         url = intertrac.get(ns + '.url')
         if not url and ns == 'trac':
                 title = _('%(target)s in %(name)s', target=target, name=name)
             else:
                 title = name
-            return self._make_ext_link(url, label, title)
+            return (url, title)
         else:
             return None
 
             raw_url = url = desc = unquote(formatter.href(filespec))
         elif len(parts) == 3:                 # realm:id:attachment-filename
             realm, id, filename = parts
-            attachment = Resource(realm, id).child('attachment', filename)
+            it = formatter.get_intertrac_url(realm, "%s:%s" % (id, filename))
+            if(it != None):
+                raw_url = url = it[0]
+                desc = it[1]
+            else:
+                attachment = Resource(realm, id).child('attachment', filename)
         elif len(parts) == 2:
             # FIXME: somehow use ResourceSystem.get_known_realms()
             #        ... or directly trac.wiki.extract_link