def url(self, url, text=None, css=None, show_image=True, **kw): """ Keyword params: title - title attribute ... some more (!!! TODO) """ url = wikiutil.mapURL(url) pretty = kw.get('pretty_url', 0) title = kw.get('title', None) if show_image and not pretty and wikiutil.isPicture(url): return (u'<img src="%s" alt="%s">' % (url, url)).encode(config.charset) if text is None: text = url # create link str = '<a' if css: str = '%s class="%s"' % (str, css) if title: str = '%s title="%s"' % (str, title) str = '%s href="%s">%s</a>' % (str, wikiutil.escape(url, 1), text) if type(str) == unicode: str = str.encode(config.charset) return str
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)
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)