PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/blog/templatetags/nofollow.py

https://bitbucket.org/resplin/byteflow
Python | 18 lines | 13 code | 4 blank | 1 comment | 0 complexity | 048d33c30bf90aefc63057380f2ceac6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # -*- mode: python; coding: utf-8; -*-
  2. from django.template import Library
  3. import re
  4. register = Library()
  5. r_nofollow = re.compile('<a (?![^>]*nofollow)')
  6. s_nofollow = '<a rel="nofollow" '
  7. def nofollow(value):
  8. """Add a rel="nofollow" attribute to its value.
  9. Value should be a proper anchor tag.
  10. """
  11. return r_nofollow.sub(s_nofollow, value)
  12. register.filter(nofollow)