add an unsafecommonmark template filter for user generated commonmark, uses bleach to clean

This commit is contained in:
Thomas Steen Rasmussen 2016-08-15 09:22:48 +02:00
parent 2b16bc4901
commit 0d0a42209f
3 changed files with 10 additions and 2 deletions

View file

@ -10,6 +10,14 @@ register = template.Library()
@register.filter
@stringfilter
def commonmark(value):
parser = CommonMark.Parser()
renderer = CommonMark.HtmlRenderer()
ast = parser.parse(value)
return mark_safe(renderer.render(ast))
@register.filter
@stringfilter
def unsafecommonmark(value):
parser = CommonMark.Parser()
renderer = CommonMark.HtmlRenderer()
ast = parser.parse(bleach.clean(value))

View file

@ -9,7 +9,7 @@ Village: {{ village.name }} | {{ block.super }}
<h3>{{ village.name }}</h3>
{{ village.description|commonmark }}
{{ village.description|unsafecommonmark }}
{% if user == village.contact %}
<hr />

View file

@ -44,7 +44,7 @@ Villages | {{ block.super }}
</a>
</td>
<td>
{{ village.description|commonmark|truncatewords:50 }}
{{ village.description|unsafecommonmark|truncatewords:50 }}
</td>
<td>
<i class="glyphicon glyphicon-{% if village.private %}remove{% else %}ok{% endif %}"></i>