def markdown_to_html(md): html = markdown(md) allowed_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'span' ] + ['h%d' % i for i in range(1, 7) ] html = bleach.clean(html, tags=allowed_tags) return mark_safe(html)