From 5b3f2f6563e47dfbf362af2a253253fd01fde033 Mon Sep 17 00:00:00 2001 From: Jakob Krigovsky Date: Sat, 17 May 2025 09:03:40 +0200 Subject: [PATCH] Linkify plain URLs in notes (#1051) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Linkify plain URLs in notes * add test case --------- Co-authored-by: Sascha Ißbrücker --- bookmarks/templatetags/shared.py | 3 ++- bookmarks/tests/test_bookmarks_list_template.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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 = '

https://example.com

' + self.assertNotes(html, note_html, 1) + def test_note_cleans_html(self): self.setup_bookmark(notes='') self.setup_bookmark(