bornhack-website/utils/templatetags/commonmark.py

18 lines
406 B
Python
Raw Normal View History

2016-08-15 07:16:07 +00:00
import CommonMark, bleach
from django import template
2016-08-15 07:16:07 +00:00
from django.utils.safestring import mark_safe
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def commonmark(value):
parser = CommonMark.Parser()
renderer = CommonMark.HtmlRenderer()
2016-08-15 07:16:07 +00:00
ast = parser.parse(bleach.clean(value))
return mark_safe(renderer.render(ast))