Created
October 5, 2008 05:39
-
-
Save igorgue/14848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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