4 URLIZE_RE = '(%s)' % '|'.join([
5 r'<(?:f|ht)tps?://[^>]*>',
6 r'\b(?:f|ht)tps?://[^)<>\s]+[^.,)<>\s]',
7 r'\bwww\.[^)<>\s]+[^.,)<>\s]',
8 r'[^(<\s]+\.(?:com|net|org)\b',
11 class UrlizePattern(markdown.inlinepatterns.Pattern):
12 """ Return a link Element given an autolink (`http://example/com`). """
13 def handleMatch(self, m):
16 if url.startswith('<'):
21 if not url.split('://')[0] in ('http','https','ftp'):
22 if '@' in url and not '/' in url:
27 el = markdown.etree.Element("a")
29 el.text = markdown.AtomicString(text)
32 class UrlizeExtension(markdown.Extension):
33 """ Urlize Extension for Python-Markdown. """
35 def extendMarkdown(self, md, md_globals):
36 """ Replace autolink with UrlizePattern """
37 md.inlinePatterns['autolink'] = UrlizePattern(URLIZE_RE, md)
39 def makeExtension(configs=None):
40 return UrlizeExtension(configs=configs)
42 if __name__ == "__main__":