working on village description escaping
This commit is contained in:
parent
14644b1b45
commit
fa6f168070
|
@ -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))
|
|
||||||
)
|
|
||||||
|
|
|
@ -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 />
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue