Mercurial > p > roundup > code
comparison roundup/cgi/templating.py @ 1394:d5314bfab0c0
fix incorrect hyperlinking markup
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 21 Jan 2003 22:34:18 +0000 |
| parents | 8e4c3e8de96f |
| children | 27586da5557c |
comparison
equal
deleted
inserted
replaced
| 1393:71928bf79302 | 1394:d5314bfab0c0 |
|---|---|
| 764 if isinstance(other, HTMLProperty): | 764 if isinstance(other, HTMLProperty): |
| 765 return cmp(self._value, other._value) | 765 return cmp(self._value, other._value) |
| 766 return cmp(self._value, other) | 766 return cmp(self._value, other) |
| 767 | 767 |
| 768 class StringHTMLProperty(HTMLProperty): | 768 class StringHTMLProperty(HTMLProperty): |
| 769 url_re = re.compile(r'\w{3,6}://\S+') | 769 hyper_re = re.compile(r'((?P<url>\w{3,6}://\S+)|' |
| 770 email_re = re.compile(r'[\w\.]+@[\w\.\-]+') | 770 r'(?P<email>[\w\.]+@[\w\.\-]+)|' |
| 771 designator_re = re.compile(r'([a-z_]+)(\d+)') | 771 r'(?P<item>(?P<class>[a-z_]+)(?P<id>\d+)))') |
| 772 def _url_repl(self, match): | 772 def _hyper_repl(self, match): |
| 773 s = match.group(0) | 773 if match.group('url'): |
| 774 return '<a href="%s">%s</a>'%(s, s) | 774 s = match.group('url') |
| 775 def _email_repl(self, match): | 775 return '<a href="%s">%s</a>'%(s, s) |
| 776 s = match.group(0) | 776 elif match.group('email'): |
| 777 return '<a href="mailto:%s">%s</a>'%(s, s) | 777 s = match.group('email') |
| 778 def _designator_repl(self, match): | 778 return '<a href="mailto:%s">%s</a>'%(s, s) |
| 779 s = match.group(0) | 779 else: |
| 780 s1 = match.group(1) | 780 s = match.group('item') |
| 781 s2 = match.group(2) | 781 s1 = match.group('class') |
| 782 try: | 782 s2 = match.group('id') |
| 783 # make sure s1 is a valid tracker classname | 783 try: |
| 784 self._db.getclass(s1) | 784 # make sure s1 is a valid tracker classname |
| 785 return '<a href="%s">%s %s</a>'%(s, s1, s2) | 785 self._db.getclass(s1) |
| 786 except KeyError: | 786 return '<a href="%s">%s %s</a>'%(s, s1, s2) |
| 787 return '%s%s'%(s1, s2) | 787 except KeyError: |
| 788 return '%s%s'%(s1, s2) | |
| 788 | 789 |
| 789 def plain(self, escape=0, hyperlink=0): | 790 def plain(self, escape=0, hyperlink=0): |
| 790 ''' Render a "plain" representation of the property | 791 ''' Render a "plain" representation of the property |
| 791 | 792 |
| 792 "escape" turns on/off HTML quoting | 793 "escape" turns on/off HTML quoting |
| 800 else: | 801 else: |
| 801 s = str(self._value) | 802 s = str(self._value) |
| 802 if hyperlink: | 803 if hyperlink: |
| 803 if not escape: | 804 if not escape: |
| 804 s = cgi.escape(s) | 805 s = cgi.escape(s) |
| 805 s = self.url_re.sub(self._url_repl, s) | 806 s = self.hyper_re.sub(self._hyper_repl, s) |
| 806 s = self.email_re.sub(self._email_repl, s) | |
| 807 s = self.designator_re.sub(self._designator_repl, s) | |
| 808 return s | 807 return s |
| 809 | 808 |
| 810 def stext(self, escape=0): | 809 def stext(self, escape=0): |
| 811 ''' Render the value of the property as StructuredText. | 810 ''' Render the value of the property as StructuredText. |
| 812 | 811 |
