/apps/blog/templatetags/nofollow.py
Python | 18 lines | 13 code | 4 blank | 1 comment | 0 complexity | 048d33c30bf90aefc63057380f2ceac6 MD5 | raw file
Possible License(s): BSD-3-Clause
- # -*- 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)