working on village description escaping

This commit is contained in:
Thomas Steen Rasmussen 2016-08-15 09:03:28 +02:00
parent 14644b1b45
commit fa6f168070
3 changed files with 8 additions and 9 deletions

View file

@ -1,17 +1,16 @@
import CommonMark
from django import template
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter(is_safe=True)
@register.filter
@stringfilter
def commonmark(value):
parser = CommonMark.Parser()
renderer = CommonMark.HtmlRenderer()
ast = parser.parse(force_text(value))
return mark_safe(
force_text(renderer.render(ast))
)
ast = parser.parse(value)
return renderer.render(ast)

View file

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

View file

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