From 1c587ac693a1432e95494f07138951bd7c5abcab Mon Sep 17 00:00:00 2001 From: Abdun Nihaal Date: Mon, 14 Apr 2025 12:58:33 +0530 Subject: [PATCH] templatetags: Render links as XHTML links 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 Closes: #591 (cherry picked from commit 980b27097a11c330b78b730d2877c2ea34c6a9e6) --- patchwork/templatetags/syntax.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/patchwork/templatetags/syntax.py b/patchwork/templatetags/syntax.py index 64773e5a..d5cf405b 100644 --- a/patchwork/templatetags/syntax.py +++ b/patchwork/templatetags/syntax.py @@ -47,6 +47,10 @@ _comment_span_res = [ _span = '%s' +_comment_link_re = re.compile(r'(https|http|git|ftp)://[^<)\s]+', re.I) + +_link = '%s' + @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) -- 2.47.3