Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gloomy-ghost committed Oct 1, 2018
1 parent f1a4478 commit 13426ca
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion isso/utils/html.py
Expand Up @@ -27,10 +27,33 @@ def __init__(self, elements, attributes):
# href for <a> and align for <table>
self.attributes = ["align", "href"] + attributes



def sanitize(self, text):
return bleach.clean(text, tags=self.elements,
clean_html = bleach.clean(text, tags=self.elements,
attributes=self.attributes, strip=True)

def set_links(attrs, new=False):
href_key = (None, u'href')

if href_key not in attrs:
return attrs
if attrs[href_key].startswith(u'mailto:'):
return attrs

rel_key = (None, u'rel')
rel_values = [val for val in attrs.get(rel_key, u'').split(u' ') if val]

for value in [u'nofollow', u'noopener']:
if value not in [rel_val.lower() for rel_val in rel_values]:
rel_values.append(value)

attrs[rel_key] = u' '.join(rel_values)
return attrs

linker = bleach.linkifier.Linker(callbacks=[set_links])
return linker.linkify(clean_html)


def Markdown(extensions=("strikethrough", "superscript", "autolink",
"fenced-code")):
Expand Down

0 comments on commit 13426ca

Please sign in to comment.