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 import CommonMark
from django import template from django import template
from django.utils.encoding import force_text from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
register = template.Library() register = template.Library()
@register.filter(is_safe=True) @register.filter
@stringfilter
def commonmark(value): def commonmark(value):
parser = CommonMark.Parser() parser = CommonMark.Parser()
renderer = CommonMark.HtmlRenderer() renderer = CommonMark.HtmlRenderer()
ast = parser.parse(force_text(value)) ast = parser.parse(value)
return mark_safe( return renderer.render(ast)
force_text(renderer.render(ast))
)

View file

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

View file

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