diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -1279,16 +1279,26 @@ def _urlify_text(s): """ return url_re.sub(_urlify_text_replace, s) -def urlify_text(s, truncate=None, stylize=False, truncatef=truncate): + +def urlify_text(s, repo_name=None, link_=None, truncate=None, stylize=False, truncatef=truncate): """ - Extract urls from text and make literal html links out of them + Parses given text message and make literal html with markup. + The text will be truncated to the specified length. + Hashes are turned into changeset links to specified repository. + URLs links to what they say. + 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: s = truncatef(s, truncate, whole_word=True) s = html_escape(s) + if repo_name is not None: + s = urlify_changesets(s, repo_name) if stylize: s = desc_stylize(s) s = _urlify_text(s) + if repo_name is not None: + s = urlify_issues(s, repo_name, link_) return literal(s) @@ -1328,24 +1338,6 @@ def linkify_others(t, l): return ''.join(links) -def urlify_commit(text_, repo_name, link_=None): - """ - Parses given text message and makes proper links. - Issues are linked to given issue-server. If link_ is provided, all other - text will link there. - """ - newtext = html_escape(text_) - - # urlify changesets - extract revisions and make link out of them - newtext = urlify_changesets(newtext, repo_name) - - # extract http/https links and make them real urls - newtext = _urlify_text(newtext) - - newtext = urlify_issues(newtext, repo_name, link_) - - return literal(newtext) - def _urlify_issues_replace_f(repo_name, ISSUE_SERVER_LNK, ISSUE_PREFIX): def urlify_issues_replace(match_obj): diff --git a/kallithea/templates/admin/gists/show.html b/kallithea/templates/admin/gists/show.html --- a/kallithea/templates/admin/gists/show.html +++ b/kallithea/templates/admin/gists/show.html @@ -70,7 +70,7 @@ ${h.gravatar_div(h.email_or_none(c.file_changeset.author), size=16)}
${h.literal(sr['message_hl'])}
%else:
-
+
%endif
diff --git a/kallithea/tests/other/test_libs.py b/kallithea/tests/other/test_libs.py
--- a/kallithea/tests/other/test_libs.py
+++ b/kallithea/tests/other/test_libs.py
@@ -351,7 +351,7 @@ class TestLibs(TestController):
"""@mention @someone""",
""),
("deadbeefcafe 123412341234",
- """deadbeefcafe 123412341234""",
+ """deadbeefcafe 123412341234""",
""),
# tags are covered by test_tag_extractor
])
@@ -359,7 +359,19 @@ class TestLibs(TestController):
from kallithea.lib.helpers import urlify_text
expected = self._quick_url(expected,
tmpl="""%s""", url_=url_)
- assert urlify_text(sample, stylize=True) == expected
+ assert urlify_text(sample, 'repo_name', stylize=True) == expected
+
+ @parametrize('sample,expected', [
+ ("deadbeefcafe @mention, and http://foo.bar/ yo",
+ """"""
+ """deadbeefcafe"""
+ """ @mention, and """
+ """http://foo.bar/"""
+ """ yo"""),
+ ])
+ def test_urlify_link(self, sample, expected):
+ from kallithea.lib.helpers import urlify_text
+ assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
@parametrize('test,expected', [
("", None),