Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/bleach/callbacks.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
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 |