comparison env/lib/python3.7/site-packages/bleach/callbacks.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 """A set of basic callbacks for bleach.linkify."""
2 from __future__ import unicode_literals
3
4
5 def nofollow(attrs, new=False):
6 href_key = (None, 'href')
7
8 if href_key not in attrs:
9 return attrs
10
11 if attrs[href_key].startswith('mailto:'):
12 return attrs
13
14 rel_key = (None, 'rel')
15 rel_values = [val for val in attrs.get(rel_key, '').split(' ') if val]
16 if 'nofollow' not in [rel_val.lower() for rel_val in rel_values]:
17 rel_values.append('nofollow')
18 attrs[rel_key] = ' '.join(rel_values)
19
20 return attrs
21
22
23 def target_blank(attrs, new=False):
24 href_key = (None, 'href')
25
26 if href_key not in attrs:
27 return attrs
28
29 if attrs[href_key].startswith('mailto:'):
30 return attrs
31
32 attrs[(None, 'target')] = '_blank'
33 return attrs