From: Abdun Nihaal Date: Mon, 14 Apr 2025 07:28:33 +0000 (+0530) Subject: templatetags: Render links as XHTML links X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c587ac693a1432e95494f07138951bd7c5abcab;p=thirdparty%2Fpatchwork.git 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) --- 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)