Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 1336:6a54b51b1784
hyperlinking of special message text
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 15 Dec 2002 23:55:34 +0000 |
| parents | e2d51ba4f6b1 |
| children | 9cf1e5583f60 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Sun Dec 15 23:55:16 2002 +0000 +++ b/roundup/cgi/templating.py Sun Dec 15 23:55:34 2002 +0000 @@ -734,14 +734,44 @@ return cmp(self._value, other) class StringHTMLProperty(HTMLProperty): - def plain(self, escape=0): + 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) + + def plain(self, escape=0, hyperlink=1): ''' Render a "plain" representation of the property + + "escape" turns on/off HTML quoting + "hyperlink" turns on/off in-text hyperlinking of URLs, email + addresses and designators ''' if self._value is None: return '' if escape: - return cgi.escape(str(self._value)) - return str(self._value) + s = cgi.escape(str(self._value)) + else: + s = self._value + if hyperlink: + 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) + return s def stext(self, escape=0): ''' Render the value of the property as StructuredText.
