1"""A set of basic callbacks for bleach.linkify."""
2
3
4def nofollow(attrs, new=False):
5 href_key = (None, "href")
6
7 if href_key not in attrs:
8 return attrs
9
10 if attrs[href_key].startswith("mailto:"):
11 return attrs
12
13 rel_key = (None, "rel")
14 rel_values = [val for val in attrs.get(rel_key, "").split(" ") if val]
15 if "nofollow" not in [rel_val.lower() for rel_val in rel_values]:
16 rel_values.append("nofollow")
17 attrs[rel_key] = " ".join(rel_values)
18
19 return attrs
20
21
22def target_blank(attrs, new=False):
23 href_key = (None, "href")
24
25 if href_key not in attrs:
26 return attrs
27
28 if attrs[href_key].startswith("mailto:"):
29 return attrs
30
31 attrs[(None, "target")] = "_blank"
32 return attrs