Skip to content

Instantly share code, notes, and snippets.

@igorgue
Created October 5, 2008 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorgue/14848 to your computer and use it in GitHub Desktop.
Save igorgue/14848 to your computer and use it in GitHub Desktop.
import re
from django import template
register = template.Library()
@register.filter
def twitter_user(message):
"""convert a "user:" to a link in twitter: <a href="htt://twitter.com/user>@user</a>"""
pattern = re.compile('[A-Za-z0-9]+:')
user = pattern.findall(message)[0]
return message.replace(user, '<a href="http://twitter.com/' + user[:-1] + '">' + user + '</a>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment