python - Django - Rendering Markdown Sanitizied with Bleach -
when markdown(text), without bleach, desired result (raw):
<p>blah</p>
and displays correctly as:
blah
where "p" tags rendered correctly paragraph block.
when bleach.clean(markdown.markdown(text)), (raw):
<p>blah</p>
and displays incorrectly as:
<p>blah</p>
where "p" tags part of text , not html paragraph block.
you need mark bleach
ed html safe
from django.utils.safestring import mark_safe ... return mark_safe(bleach.clean(markdown.markdown(text)))
but, there django-bleach provides integration django , ready-made tags use bleach in django.
{% load markdown_deux_tags bleach_tags %} {{ view_user.profile.about|markdown:"user"|bleach }}
in settings.py
can tell django-bleach tags okay
bleach_allowed_tags = ['h1', 'h2', 'p', 'b', 'i', 'strong', 'a'] bleach_allowed_attributes = ['href', 'title', 'style'] bleach_allowed_styles = ['font-family', 'font-weight'] bleach_strip_tags = true
etc.
Comments
Post a Comment