Changes between Version 1 and Version 2 of LinkifyFilter


Ignore:
Timestamp:
Apr 12, 2009, 12:24:19 PM (16 years ago)
Author:
Collin Anderson
Comment:

Coding Style

Legend:

Unmodified
Added
Removed
Modified
  • LinkifyFilter

    v1 v2  
    66
    77register = template.Library()
    8 regex = re.compile( r'(([a-zA-Z]+)://[^ \t\n\r]+)', re.MULTILINE )
     8regex = re.compile(r'(([a-zA-Z]+)://[^ \t\n\r]+)', re.MULTILINE)
    99
    10 def linkify( value, arg = '' ):
    11     def _spacify( s, chars = 40 ):
     10def linkify(value, arg=''):
     11    def _spacify(s, chars=40):
    1212        if len(s) <= chars:
    1313            return s
    14         for k in range( len(s) / chars ):
     14        for k in range(len(s) / chars):
    1515            pos = (k + 1) * chars
    1616            s = s[0:pos] + ' ' + s[pos:]
    1717        return s
    18     def _replace( match ):
    19         href = match.group( 0 )
     18    def _replace(match):
     19        href = match.group(0)
    2020        cls = ' class="%s"' % arg if arg else ''
    2121        return '<a href="%s"%s>%s</a>' % (href, cls, _spacify(href))
    22     return regex.sub( _replace, value )
     22    return regex.sub(_replace, value)
    2323
    24 register.filter( 'linkify', linkify )
     24register.filter('linkify', linkify)
    2525}}}
    2626
Back to Top