diff --git a/bookmarks/templatetags/shared.py b/bookmarks/templatetags/shared.py index 5da3c1c..297c453 100644 --- a/bookmarks/templatetags/shared.py +++ b/bookmarks/templatetags/shared.py @@ -142,5 +142,6 @@ def render_markdown(context, markdown_text): as_html = renderer.convert(markdown_text) sanitized_html = bleach.clean(as_html, markdown_tags, markdown_attrs) + linkified_html = bleach.linkify(sanitized_html) - return mark_safe(sanitized_html) + return mark_safe(linkified_html) diff --git a/bookmarks/tests/test_bookmarks_list_template.py b/bookmarks/tests/test_bookmarks_list_template.py index 46ed290..802ae45 100644 --- a/bookmarks/tests/test_bookmarks_list_template.py +++ b/bookmarks/tests/test_bookmarks_list_template.py @@ -884,6 +884,21 @@ class BookmarkListTemplateTest(TestCase, BookmarkFactoryMixin, HtmlTestMixin): ) self.assertNotes(html, note_html, 1) + def test_note_renders_markdown_with_linkify(self): + # Should linkify plain URL + self.setup_bookmark(notes="Example: https://example.com") + html = self.render_template() + + note_html = '
Example: https://example.com
' + self.assertNotes(html, note_html, 1) + + # Should not linkify URL in markdown link + self.setup_bookmark(notes="[https://example.com](https://example.com)") + html = self.render_template() + + note_html = '' + self.assertNotes(html, note_html, 1) + def test_note_cleans_html(self): self.setup_bookmark(notes='') self.setup_bookmark(