aboutsummaryrefslogtreecommitdiff
path: root/bleach/callbacks.py
blob: 227f089868b7f22fd19d8d6315d0df8fbfbc0306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""A set of basic callbacks for bleach.linkify."""
from __future__ import unicode_literals


def nofollow(attrs, new=False):
    if attrs['href'].startswith('mailto:'):
        return attrs
    rel = [x for x in attrs.get('rel', '').split(' ') if x]
    if not 'nofollow' in [x.lower() for x in rel]:
        rel.append('nofollow')
    attrs['rel'] = ' '.join(rel)

    return attrs


def target_blank(attrs, new=False):
    if attrs['href'].startswith('mailto:'):
        return attrs
    attrs['target'] = '_blank'
    return attrs