Skip to content

Instantly share code, notes, and snippets.

@Perlmint
Created August 4, 2015 02:58
Show Gist options
  • Save Perlmint/8c33b068cee6c0326b08 to your computer and use it in GitHub Desktop.
Save Perlmint/8c33b068cee6c0326b08 to your computer and use it in GitHub Desktop.
test
from bleach import clean, linkify, callbacks
content = '<aaaa https://google.com'
def sep():
print '====================='
def custom_linkify(text):
return linkify(text, parse_email=True,
callbacks=[callbacks.nofollow, callbacks.target_blank])
sep()
print custom_linkify(clean(content, tags=list()))
# blank
sep()
print custom_linkify(content.replace('<', '&lt;').replace('>', '&gt;'))
# &lt;aaaa &lt;a="" href="&amp;lt;a href=" https:="" google.com"="" target="_blank" rel="nofollow"&gt;https://google.com" target="_blank" rel="nofollow"&gt;<a href="https://google.com" rel="nofollow" target="_blank">https://google.com</a>
sep()
print custom_linkify('&lt;aaaa https://google.com')
# &lt;aaaa &lt;a="" href="&amp;lt;a href=" https:="" google.com"="" target="_blank" rel="nofollow"&gt;https://google.com" target="_blank" rel="nofollow"&gt;<a href="https://google.com" rel="nofollow" target="_blank">https://google.com</a>
sep()
print custom_linkify(content).replace('<', '&lt;').replace('>', '&gt;')
# blank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment