From 4aea8e0b36196b48e587eb8cdedd29ea8dc1cd1e 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 --- 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 @@ def _compile(value): _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)