Skip to content

Commit 4aea8e0

Browse files
committed
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 <[email protected]> Closes: #591
1 parent 1c3e4d4 commit 4aea8e0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

patchwork/templatetags/syntax.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def _compile(value):
4747

4848
_span = '<span class="%s">%s</span>'
4949

50+
_comment_link_re = re.compile(r'(https|http|git|ftp)://[^<)\s]+', re.I)
51+
52+
_link = '<a href="%s">%s</a>'
53+
5054

5155
@register.filter
5256
def patchsyntax(patch):
@@ -74,5 +78,8 @@ def commentsyntax(submission):
7478

7579
for r, cls in _comment_span_res:
7680
content = r.sub(lambda x: _span % (cls, x.group(0)), content)
81+
content = _comment_link_re.sub(
82+
lambda x: _link % (x.group(0), x.group(0)), content
83+
)
7784

7885
return mark_safe(content)

0 commit comments

Comments
 (0)