From fa6f168070cb7e2662deb64b4583fc903f1580eb Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Mon, 15 Aug 2016 09:03:28 +0200 Subject: [PATCH] working on village description escaping --- utils/templatetags/commonmark.py | 13 ++++++------- villages/templates/village_detail.html | 2 +- villages/templates/village_list.html | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/utils/templatetags/commonmark.py b/utils/templatetags/commonmark.py index 6b885e61..7a35fa47 100644 --- a/utils/templatetags/commonmark.py +++ b/utils/templatetags/commonmark.py @@ -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)) - ) \ No newline at end of file + ast = parser.parse(value) + return renderer.render(ast) + diff --git a/villages/templates/village_detail.html b/villages/templates/village_detail.html index 79925536..2768515f 100644 --- a/villages/templates/village_detail.html +++ b/villages/templates/village_detail.html @@ -9,7 +9,7 @@ Village: {{ village.name }} | {{ block.super }}

{{ village.name }}

-{{ village.description|commonmark }} +{{ village.description|escape|commonmark }} {% if user == village.contact %}
diff --git a/villages/templates/village_list.html b/villages/templates/village_list.html index 185d510c..e7d744eb 100644 --- a/villages/templates/village_list.html +++ b/villages/templates/village_list.html @@ -44,7 +44,7 @@ Villages | {{ block.super }} - {{ village.description|truncatewords:50|commonmark }} + {{ village.description|commonmark|truncatewords:50 }}