add an unsafecommonmark template filter for user generated commonmark, uses bleach to clean
This commit is contained in:
parent
2b16bc4901
commit
0d0a42209f
|
@ -10,6 +10,14 @@ register = template.Library()
|
||||||
@register.filter
|
@register.filter
|
||||||
@stringfilter
|
@stringfilter
|
||||||
def commonmark(value):
|
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()
|
parser = CommonMark.Parser()
|
||||||
renderer = CommonMark.HtmlRenderer()
|
renderer = CommonMark.HtmlRenderer()
|
||||||
ast = parser.parse(bleach.clean(value))
|
ast = parser.parse(bleach.clean(value))
|
||||||
|
|
|
@ -9,7 +9,7 @@ Village: {{ village.name }} | {{ block.super }}
|
||||||
|
|
||||||
<h3>{{ village.name }}</h3>
|
<h3>{{ village.name }}</h3>
|
||||||
|
|
||||||
{{ village.description|commonmark }}
|
{{ village.description|unsafecommonmark }}
|
||||||
|
|
||||||
{% 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|commonmark|truncatewords:50 }}
|
{{ village.description|unsafecommonmark|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