Created
June 13, 2011 16:42
-
-
Save timmyomahony/1023144 to your computer and use it in GitHub Desktop.
twittify: django template filter to replace metions (@'s) and hashtags (#'s) with links to twitter
This file contains hidden or 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
@register.filter(name='twittify') | |
def twittify(value): | |
""" Replace @ and #'s with links to twitter""" | |
return mark_safe( | |
re.sub(r"#(?P<ht>([a-zA-Z0-9_])+)", r"#<a href='http://twitter.com/#!/search?q=\g<ht>' target='_blank'>\g<ht></a>", | |
re.sub(r"@(?P<un>([a-zA-Z0-9_]){1,15})", r"@<a href='http://twitter.com/\g<un>' target='_blank'>\g<un></a>", value)) | |
) | |
twittify.mark_safe=True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment