From 151484dee39d09cc68123930c1c437166c76ca63 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Fri, 8 Jun 2018 19:35:14 +0200 Subject: [PATCH] Support parsing of bare links in Markdown text --- pillar/markdown.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pillar/markdown.py b/pillar/markdown.py index 6a44ff4a..daf53ee6 100644 --- a/pillar/markdown.py +++ b/pillar/markdown.py @@ -45,11 +45,15 @@ ALLOWED_STYLES = [ def markdown(s: str) -> str: commented_shortcodes = shortcodes.comment_shortcodes(s) tainted_html = CommonMark.commonmark(commented_shortcodes) - safe_html = bleach.clean(tainted_html, - tags=ALLOWED_TAGS, + + # Create a Cleaner that supports parsing of bare links (see filters). + cleaner = bleach.Cleaner(tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, styles=ALLOWED_STYLES, - strip_comments=False) + strip_comments=False, + filters=[bleach.linkifier.LinkifyFilter]) + + safe_html = cleaner.clean(tainted_html) return safe_html