Mercurial > kallithea
changeset 6182:6944df7de4e1
helpers: add @mentions to ordinary urlify_text and use urlify_text for render_w_mentions
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | 41882a2d41ef |
children | 4e2e6371f79a |
files | kallithea/lib/helpers.py kallithea/tests/other/test_libs.py |
diffstat | 2 files changed, 9 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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('<div class="formatted-fixed">%s</div>' % s)
--- 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""", + """<b>@mention</b> <b>@someone</b>""", ""), ("deadbeefcafe 123412341234", """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a> <a class="revision-link" href="/repo_name/changeset/123412341234">123412341234</a>""", @@ -365,7 +364,7 @@ ("deadbeefcafe @mention, and http://foo.bar/ yo", """<a class="message-link" href="#the-link"></a>""" """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a>""" - """<a class="message-link" href="#the-link"> @mention, and </a>""" + """<a class="message-link" href="#the-link"> <b>@mention</b>, and </a>""" """<a href="http://foo.bar/">http://foo.bar/</a>""" """<a class="message-link" href="#the-link"> yo</a>"""), ])