Example #1
0
 def _url_repl(self, word):
     """
     Handle literal URLs including inline images.
     """
     scheme = word.split(":", 1)[0]
     if not (scheme == "http"):
             if scheme == "wiki":
                 return self.interwiki([word])
             return self.formatter.url(word, text=self.highlight_text(word))
     elif scheme == "http":
             words = word.split(':', 1)
             if wikiutil.isPicture(word) and re.match(self.url_rule, word):
                     text = self.formatter.image(title=word, alt=word,
                                                 src=word)
                     return self.formatter.rawHTML(text)
             else:
                     text = web.getLinkIcon(self.request, self.formatter,
                                            scheme)
                     text += self.highlight_text(word)
             return self.formatter.url(word, text, 'external', pretty_url=1,
                                       unescaped=1)
Example #2
0
    def _url_bracket_repl(self, word):
        """
        Handle bracketed URLs.
        """
        # Local extended link?
        if word[1] == ':':
            words = word[2:-1].split(':', 1)
            if len(words) == 1:
                words = words * 2
            return self._word_repl(words[0], words[1])

        # Traditional split on space
        words = word[1:-1].split(None, 1)

        if words[0][0] == '#':
            # anchor link
            if len(words) > 1:
                return self.formatter.url(
                    words[0], self.highlight_text(words[1]))
            else:
                return self.formatter.url(
                    words[0], self.highlight_text(words[0][1:]))

        scheme = words[0].split(":", 1)[0]
        if scheme == "wiki":
            words = wikiutil.format_interwiki_words(words)
            return self.interwiki(words, pretty_url=1)

        if (len(words) == 1 and wikiutil.isPicture(words[0]) and
            re.match(self.url_rule, words[0])):
            text = self.formatter.image(title=words[0], alt=words[0],
                                        src=words[0])
        else:
            text = web.getLinkIcon(self.request, self.formatter, scheme)
            if len(words) == 1:
                text += self.highlight_text(words[0])
            else:
                text += self.highlight_text(words[1])
        return self.formatter.url(words[0], text, 'external', pretty_url=1,
                                  unescaped=1)