Skip to content

Instantly share code, notes, and snippets.

@muhammad-ammar
Created September 22, 2016 12:56
Show Gist options
  • Save muhammad-ammar/c712500596df62d917973f6e40d53608 to your computer and use it in GitHub Desktop.
Save muhammad-ammar/c712500596df62d917973f6e40d53608 to your computer and use it in GitHub Desktop.
import bleach
import markupsafe
from mako.template import Template
def HTML(html):
return markupsafe.Markup(html)
def remove_markup(html):
return bleach.clean(html, tags=[], strip=True)
template = """
<%page expression_filter="h"/>
${html}
"""
data = "<b>Rock & Roll</b>"
bleached_html = remove_markup(data)
HTML_bleached_html = HTML(remove_markup(data))
mytemplate = Template(template)
print mytemplate.render_unicode(html=bleached_html)
print mytemplate.render_unicode(html=HTML_bleached_html)
####### OUTPUT
# Rock &amp;amp; Roll
# Rock &amp;amp; Roll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment