Now markdown urls also work.
This commit is contained in:
parent
481a7d1a95
commit
ecfe7dc385
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue