Serotonin Storm

source>core>templatetags>core.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from django.template import Library
import re

register = Library()

r_nofollow = re.compile(r'<a (?![^>]*nofollow)')
s_nofollow = '<a rel="nofollow" '

r_script = re.compile(r"<script[^>]*>.*</script>")
s_script = ''

def nofollow(value):
    return r_nofollow.sub(s_nofollow, value)

def noscript(value):
    return r_script.sub(s_script, value)

register.filter(nofollow)
register.filter(noscript)