]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
templatetags: Render links as XHTML links
authorAbdun Nihaal <abdun.nihaal@gmail.com>
Mon, 14 Apr 2025 07:28:33 +0000 (12:58 +0530)
committerStephen Finucane <stephenfinucane@hotmail.com>
Sun, 7 Jun 2026 16:41:28 +0000 (17:41 +0100)
Convert links in the commit message and comments, to be rendered as
clickable XHTML links for easy navigation.

Currently only http, https, ftp and git are recognized. And only links
that are not broken across lines are recognized.

Signed-off-by: Abdun Nihaal <abdun.nihaal@gmail.com>
Closes: #591
patchwork/templatetags/syntax.py

index 64773e5ab99754d2c9d8779ae9ecaee3c815d1f6..d5cf405bafe612e7a9cc48742f723b991ba6a187 100644 (file)
@@ -47,6 +47,10 @@ _comment_span_res = [
 
 _span = '<span class="%s">%s</span>'
 
+_comment_link_re = re.compile(r'(https|http|git|ftp)://[^<)\s]+', re.I)
+
+_link = '<a href="%s">%s</a>'
+
 
 @register.filter
 def patchsyntax(patch):
@@ -74,5 +78,8 @@ def commentsyntax(submission):
 
     for r, cls in _comment_span_res:
         content = r.sub(lambda x: _span % (cls, x.group(0)), content)
+    content = _comment_link_re.sub(
+        lambda x: _link % (x.group(0), x.group(0)), content
+    )
 
     return mark_safe(content)