Commits

Anonymous committed 140a1c1

[svn] use verbose re syntax for AUTO_LINK_RE, so it resembles the rails version.
this is rails' r4994 version, with two pre-existing webhelpers changes:
o use [\.,"'?!;:] instead of ruby's [[:punct:]]
o incorporates the valid url format fix from webhelpers' r1329

  • Participants
  • Parent commits 8dcc366

Comments (0)

Files changed (1)

File webhelpers/rails/text.py

 import webhelpers.markdown as markdown
 import itertools, re
 
-AUTO_LINK_RE = re.compile(r"""(<\w+.*?>|[^=!:'"/]|^)((?:https?://)|(?:www\.))([-\w]+(?:\.[-\w]+)*(?::\d+)?(?:/(?:[~\w%.;-]+)?)*(?:\?[\w%&+=.;-]+)?(?:\#\w*)?)([\.,"'?!;:]|\s|<|$)""")
+AUTO_LINK_RE = re.compile(r"""
+                        (                        # leading text
+                          <\w+.*?>|              #   leading HTML tag, or
+                          [^=!:'"/]|             #   leading punctuation, or 
+                          ^                      #   beginning of line
+                        )
+                        (
+                          (?:https?://)|         # protocol spec, or
+                          (?:www\.)              # www.*
+                        ) 
+                        (
+                          [-\w]+                 # subdomain or domain
+                          (?:\.[-\w]+)*          # remaining subdomains or domain
+                          (?::\d+)?              # port
+                          (?:/(?:[~\w%.;-]+)?)*  # path
+                          (?:\?[\w%&+=.;-]+)?    # query string
+                          (?:\#\w*)?             # trailing anchor
+                        )
+                        ([\.,"'?!;:]|\s|<|$)     # trailing text
+                           """, re.X)
     
 def iterdict(items):
     return dict(items=items, iter=itertools.cycle(items))