Commits

David Cramer committed 24e987c

Some initial fixes for the auto detection linking

  • Participants
  • Parent commits f2c6506

Comments (0)

Files changed (1)

File bbcode/bbtags/web.py

     
     
 class AutoDetectURL(SelfClosingTagNode):
-    open_pattern = re.compile('[^[\]](?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~/|/'
+    open_pattern = re.compile(r'(?P<before>[^[\]])(?P<url>(?P<protocol>(?:ht|f)tp(?:s?)\:\/\/|~/|/'
                               ')?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomain'
                               's)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org'
                               '|net|gov|mil|biz|info|mobi|name|aero|jobs|museum'
                               '%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)('
                               '?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.'
                               ',*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+'
-                              '|.,*:=]|%[a-f\d]{2})*)?[^[\]]')
+                              '|.,*:=]|%[a-f\d]{2})*)?)(?P<after>[^[\]])')
     
     def parse(self):
-        url = self.match.group()
-        return '<a href="%s">%s</a>' % (url, url)
+        match = self.match.groupdict()
+        match['label'] = match['url']
+        if not match.get('protocol'):
+            match['url'] = 'http://' + match['url']
+        return '%(before)s<a href="%(url)s">%(label)s</a>%(after)s' % match
     
 
 register(Url)