Linkify plain URLs in notes (#1051)

* Linkify plain URLs in notes

* add test case

---------

Co-authored-by: Sascha Ißbrücker <sascha.issbruecker@gmail.com>
This commit is contained in:
Jakob Krigovsky
2025-05-17 09:03:40 +02:00
committed by GitHub
parent 04065f8079
commit 5b3f2f6563
2 changed files with 17 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 = '<p>Example: <a href="https://example.com" rel="nofollow">https://example.com</a></p>'
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 = '<p><a href="https://example.com" rel="nofollow">https://example.com</a></p>'
self.assertNotes(html, note_html, 1)
def test_note_cleans_html(self):
self.setup_bookmark(notes='<script>alert("test")</script>')
self.setup_bookmark(