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):

&lt;p&gt;blah&lt;/p&gt; 

and displays incorrectly as:

<p>blah</p> 

where "p" tags part of text , not html paragraph block.

you need mark bleached 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

Popular posts from this blog

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

wordpress - (T_ENDFOREACH) php error -

Using django-mptt to get only the categories that have items -