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.person(c.file_changeset.author)} - ${_('created')} ${h.age(c.file_changeset.date)}
-
${h.urlify_commit(c.file_changeset.message,c.repo_name)}
+
${h.urlify_text(c.file_changeset.message,c.repo_name)}
diff --git a/kallithea/templates/changelog/changelog.html b/kallithea/templates/changelog/changelog.html --- a/kallithea/templates/changelog/changelog.html +++ b/kallithea/templates/changelog/changelog.html @@ -116,7 +116,7 @@ ${self.repo_context_bar('changelog', c.f
-
${h.urlify_commit(cs.message, c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
+
${h.urlify_text(cs.message, c.repo_name,h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
%if c.comments.get(cs.raw_id):
diff --git a/kallithea/templates/changelog/changelog_summary_data.html b/kallithea/templates/changelog/changelog_summary_data.html --- a/kallithea/templates/changelog/changelog_summary_data.html +++ b/kallithea/templates/changelog/changelog_summary_data.html @@ -45,7 +45,7 @@ ${h.show_id(cs)} - ${h.urlify_commit(h.chop_at(cs.message,'\n'),c.repo_name, h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))} + ${h.urlify_text(h.chop_at(cs.message,'\n'),c.repo_name, h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))} ${h.age(cs.date)} diff --git a/kallithea/templates/changeset/changeset.html b/kallithea/templates/changeset/changeset.html --- a/kallithea/templates/changeset/changeset.html +++ b/kallithea/templates/changeset/changeset.html @@ -156,7 +156,7 @@ ${self.repo_context_bar('changelog', c.c
% endif -
${h.urlify_commit(c.changeset.message, c.repo_name)}
+
${h.urlify_text(c.changeset.message, c.repo_name)}
diff --git a/kallithea/templates/changeset/changeset_range.html b/kallithea/templates/changeset/changeset_range.html --- a/kallithea/templates/changeset/changeset_range.html +++ b/kallithea/templates/changeset/changeset_range.html @@ -50,7 +50,7 @@ ${self.repo_context_bar('changelog')}
%endif -
${h.urlify_commit(h.wrap_paragraphs(cs.message),c.repo_name)}
+
${h.urlify_text(h.wrap_paragraphs(cs.message),c.repo_name)}
%endfor diff --git a/kallithea/templates/compare/compare_cs.html b/kallithea/templates/compare/compare_cs.html --- a/kallithea/templates/compare/compare_cs.html +++ b/kallithea/templates/compare/compare_cs.html @@ -73,7 +73,7 @@
%endfor -
${h.urlify_commit(cs.message, c.repo_name)}
+
${h.urlify_text(cs.message, c.repo_name)}
%endfor diff --git a/kallithea/templates/files/files_source.html b/kallithea/templates/files/files_source.html --- a/kallithea/templates/files/files_source.html +++ b/kallithea/templates/files/files_source.html @@ -51,7 +51,7 @@ ${h.gravatar_div(h.email_or_none(c.changeset.author), size=16)}
${h.person(c.changeset.author)}
-
${h.urlify_commit(c.changeset.message,c.repo_name)}
+
${h.urlify_text(c.changeset.message,c.repo_name)}
%if c.file.is_browser_compatible_image(): diff --git a/kallithea/templates/pullrequests/pullrequest_show.html b/kallithea/templates/pullrequests/pullrequest_show.html --- a/kallithea/templates/pullrequests/pullrequest_show.html +++ b/kallithea/templates/pullrequests/pullrequest_show.html @@ -43,7 +43,7 @@ ${self.repo_context_bar('showpullrequest %endif
-
${h.urlify_commit(c.pull_request.description, c.pull_request.org_repo.repo_name)}
+
${h.urlify_text(c.pull_request.description, c.pull_request.org_repo.repo_name)}
@@ -205,7 +205,7 @@ ${self.repo_context_bar('showpullrequest %endfor -
${h.urlify_commit(cs.message, c.repo_name)}
+
${h.urlify_text(cs.message, c.repo_name)}
%endif diff --git a/kallithea/templates/search/search_commit.html b/kallithea/templates/search/search_commit.html --- a/kallithea/templates/search/search_commit.html +++ b/kallithea/templates/search/search_commit.html @@ -21,7 +21,7 @@
${h.literal(sr['message_hl'])}
%else: -
${h.urlify_commit(sr['message'], sr['repository'])}
+
${h.urlify_text(sr['message'], sr['repository'])}
%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),