From bb10f4e6af85a8cb1b4c537fcfc36a463340bf53 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 21 Jan 2003 22:34:18 +0000 Subject: [PATCH] fix incorrect hyperlinking markup git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1471 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 +- roundup/cgi/templating.py | 43 +++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e9e5c5e..ab0835c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index bf2552e..3b84633 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -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 '%s'%(s, s) - def _email_repl(self, match): - s = match.group(0) - return '%s'%(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 '%s %s'%(s, s1, s2) - except KeyError: - return '%s%s'%(s1, s2) + hyper_re = re.compile(r'((?P\w{3,6}://\S+)|' + r'(?P[\w\.]+@[\w\.\-]+)|' + r'(?P(?P[a-z_]+)(?P\d+)))') + def _hyper_repl(self, match): + if match.group('url'): + s = match.group('url') + return '%s'%(s, s) + elif match.group('email'): + s = match.group('email') + return '%s'%(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 '%s %s'%(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): -- 2.39.5