Now markdown urls also work.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-03-17 15:09:32 +01:00
parent 481a7d1a95
commit ecfe7dc385

View file

@ -11,7 +11,7 @@ def parse_commonmark(value):
parser = commonmark.Parser()
renderer = commonmark.HtmlRenderer()
ast = parser.parse(value)
return mark_safe(renderer.render(ast))
return renderer.render(ast)
@register.filter(is_safe=True)
@ -19,12 +19,15 @@ def parse_commonmark(value):
def trustedcommonmark(value):
"""Returns HTML given some commonmark Markdown. Also allows real HTML, so do not use this with untrusted input."""
linkified_value = bleach.linkify(value, parse_email=True)
return parse_commonmark(linkified_value)
result = parse_commonmark(linkified_value)
return mark_safe(result)
@register.filter(is_safe=True)
@stringfilter
def untrustedcommonmark(value):
"""Returns HTML given some commonmark Markdown. Cleans actual HTML from input using bleach, suitable for use with untrusted input."""
linkified_value = bleach.linkify(bleach.clean(value), parse_email=True)
return parse_commonmark(linkified_value)
cleaned = bleach.clean(value)
markdown = parse_commonmark(cleaned)
result = bleach.linkify(markdown, parse_email=True)
return mark_safe(result)