Changes between Version 1 and Version 2 of LinkifyFilter
- Timestamp:
- Apr 12, 2009, 12:24:19 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
LinkifyFilter
v1 v2 6 6 7 7 register = template.Library() 8 regex = re.compile( r'(([a-zA-Z]+)://[^ \t\n\r]+)', re.MULTILINE)8 regex = re.compile(r'(([a-zA-Z]+)://[^ \t\n\r]+)', re.MULTILINE) 9 9 10 def linkify( value, arg = ''):11 def _spacify( s, chars = 40):10 def linkify(value, arg=''): 11 def _spacify(s, chars=40): 12 12 if len(s) <= chars: 13 13 return s 14 for k in range( len(s) / chars):14 for k in range(len(s) / chars): 15 15 pos = (k + 1) * chars 16 16 s = s[0:pos] + ' ' + s[pos:] 17 17 return s 18 def _replace( match):19 href = match.group( 0)18 def _replace(match): 19 href = match.group(0) 20 20 cls = ' class="%s"' % arg if arg else '' 21 21 return '<a href="%s"%s>%s</a>' % (href, cls, _spacify(href)) 22 return regex.sub( _replace, value)22 return regex.sub(_replace, value) 23 23 24 register.filter( 'linkify', linkify)24 register.filter('linkify', linkify) 25 25 }}} 26 26