# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID 6944df7de4e182f75f00c6af75f70288f9b1ef26 # Parent 41882a2d41efd8dc751504ad430532352c65abd9 helpers: add @mentions to ordinary urlify_text and use urlify_text for render_w_mentions diff -r 41882a2d41ef -r 6944df7de4e1 kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 @@ -1289,7 +1289,9 @@ Issues are linked to given issue-server. If link_ is provided, all text not already linking somewhere will link there. """ - if truncate is not None: + if truncate is None: + s = s.rstrip() + else: s = truncatef(s, truncate, whole_word=True) s = html_escape(s) if repo_name is not None: @@ -1299,6 +1301,7 @@ s = _urlify_text(s) if repo_name is not None: s = urlify_issues(s, repo_name, link_) + s = MENTIONS_REGEX.sub(_mentions_replace, s) return literal(s) @@ -1411,17 +1414,8 @@ Render plain text with revision hashes and issue references urlified and with @mention highlighting. """ - s = source.rstrip() - s = safe_unicode(s) - s = '\n'.join(s.splitlines()) - s = html_escape(s) - # this sequence of html-ifications seems to be safe and non-conflicting - # if the issues regexp is sane - s = _urlify_text(s) - if repo_name is not None: - s = urlify_changesets(s, repo_name) - s = urlify_issues(s, repo_name) - s = MENTIONS_REGEX.sub(_mentions_replace, s) + s = safe_unicode(source) + s = urlify_text(s, repo_name=repo_name) return literal('
%s
' % s) diff -r 41882a2d41ef -r 6944df7de4e1 kallithea/tests/other/test_libs.py --- a/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/tests/other/test_libs.py Tue Sep 06 00:51:18 2016 +0200 @@ -311,8 +311,7 @@ """Multi line\n""" """ url[123123123123]\n""" """ some text url[123123123123]\n""" - """ sometimes !\n""" - """ """), + """ sometimes !"""), ]) def test_urlify_changesets(self, sample, expected): def fake_url(self, *args, **kwargs): @@ -348,7 +347,7 @@ """ some text lalala""", "https://foo.bar.example.com"), ("@mention @someone", - """@mention @someone""", + """@mention @someone""", ""), ("deadbeefcafe 123412341234", """deadbeefcafe 123412341234""", @@ -365,7 +364,7 @@ ("deadbeefcafe @mention, and http://foo.bar/ yo", """""" """deadbeefcafe""" - """ @mention, and """ + """ @mention, and """ """http://foo.bar/""" """ yo"""), ])