/apps/blog/templatetags/nofollow.py
https://bitbucket.org/resplin/byteflow · Python · 18 lines · 12 code · 5 blank · 1 comment · 0 complexity · 048d33c30bf90aefc63057380f2ceac6 MD5 · raw file
- # -*- mode: python; coding: utf-8; -*-
- from django.template import Library
- import re
- register = Library()
- r_nofollow = re.compile('<a (?![^>]*nofollow)')
- s_nofollow = '<a rel="nofollow" '
- def nofollow(value):
- """Add a rel="nofollow" attribute to its value.
- Value should be a proper anchor tag.
- """
- return r_nofollow.sub(s_nofollow, value)
- register.filter(nofollow)