]> git.tokkee.org Git - roundup.git/commitdiff

Code

fix incorrect hyperlinking markup
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 21 Jan 2003 22:34:18 +0000 (22:34 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Tue, 21 Jan 2003 22:34:18 +0000 (22:34 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1471 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/cgi/templating.py

index e9e5c5e5d7493b113171588f111388b7e79fd121..ab0835c0ce58bd5f1706dff2b2d3a7a60f4e9388 100644 (file)
@@ -2,7 +2,7 @@ This file contains the changes to the Roundup system over time. The entries
 are given with the most recent entry first.
 
 2003-??-?? 0.6.0
-- better hyperlinking in web message texts
+- better hyperlinking in web message texts (handle ambiguous cases)
 - support setting of properties on message and file through web and
   email interface (thanks John Rouillard)
 - allow additional control over the roundupdb email sending (explicit
index bf2552eac27a515f5445567007d35a96df478fa7..3b846337b242561574aa1b944ed9edabe3ef78b9 100644 (file)
@@ -766,25 +766,26 @@ class HTMLProperty:
         return cmp(self._value, other)
 
 class StringHTMLProperty(HTMLProperty):
-    url_re = re.compile(r'\w{3,6}://\S+')
-    email_re = re.compile(r'[\w\.]+@[\w\.\-]+')
-    designator_re = re.compile(r'([a-z_]+)(\d+)')
-    def _url_repl(self, match):
-        s = match.group(0)
-        return '<a href="%s">%s</a>'%(s, s)
-    def _email_repl(self, match):
-        s = match.group(0)
-        return '<a href="mailto:%s">%s</a>'%(s, s)
-    def _designator_repl(self, match):
-        s = match.group(0)
-        s1 = match.group(1)
-        s2 = match.group(2)
-        try:
-            # make sure s1 is a valid tracker classname
-            self._db.getclass(s1)
-            return '<a href="%s">%s %s</a>'%(s, s1, s2)
-        except KeyError:
-            return '%s%s'%(s1, s2)
+    hyper_re = re.compile(r'((?P<url>\w{3,6}://\S+)|'
+                          r'(?P<email>[\w\.]+@[\w\.\-]+)|'
+                          r'(?P<item>(?P<class>[a-z_]+)(?P<id>\d+)))')
+    def _hyper_repl(self, match):
+        if match.group('url'):
+            s = match.group('url')
+            return '<a href="%s">%s</a>'%(s, s)
+        elif match.group('email'):
+            s = match.group('email')
+            return '<a href="mailto:%s">%s</a>'%(s, s)
+        else:
+            s = match.group('item')
+            s1 = match.group('class')
+            s2 = match.group('id')
+            try:
+                # make sure s1 is a valid tracker classname
+                self._db.getclass(s1)
+                return '<a href="%s">%s %s</a>'%(s, s1, s2)
+            except KeyError:
+                return '%s%s'%(s1, s2)
 
     def plain(self, escape=0, hyperlink=0):
         ''' Render a "plain" representation of the property
@@ -802,9 +803,7 @@ class StringHTMLProperty(HTMLProperty):
         if hyperlink:
             if not escape:
                 s = cgi.escape(s)
-            s = self.url_re.sub(self._url_repl, s)
-            s = self.email_re.sub(self._email_repl, s)
-            s = self.designator_re.sub(self._designator_repl, s)
+            s = self.hyper_re.sub(self._hyper_repl, s)
         return s
 
     def stext(self, escape=0):