diff --git a/kallithea/controllers/journal.py b/kallithea/controllers/journal.py --- a/kallithea/controllers/journal.py +++ b/kallithea/controllers/journal.py @@ -239,10 +239,7 @@ class JournalController(BaseController): def desc(desc): from pylons import tmpl_context as c - if c.visual.stylify_metatags: - return h.urlify_text(h.desc_stylize(h.truncate(desc, 60))) - else: - return h.urlify_text(h.truncate(desc, 60)) + return h.urlify_text(desc, truncate=60, stylize=c.visual.stylify_metatags) def repo_actions(repo_name): return _render('repo_actions', repo_name) diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -1273,10 +1273,15 @@ def _urlify_text(s): return '%(url)s' % ({'url': url_full}) return url_re.sub(url_func, s) -def urlify_text(s): +def urlify_text(s, truncate=None, stylize=False, truncatef=truncate): """ Extract urls from text and make literal html links out of them """ + if truncate is not None: + s = truncatef(s, truncate) + s = html_escape(s) + if stylize: + s = desc_stylize(s) s = _urlify_text(s) return literal(s) diff --git a/kallithea/model/repo.py b/kallithea/model/repo.py --- a/kallithea/model/repo.py +++ b/kallithea/model/repo.py @@ -209,10 +209,7 @@ class RepoModel(BaseModel): cs_cache.get('message')) def desc(desc): - if c.visual.stylify_metatags: - return h.urlify_text(h.desc_stylize(h.html_escape(h.truncate(desc, 60)))) - else: - return h.urlify_text(h.html_escape(h.truncate(desc, 60))) + return h.urlify_text(desc, truncate=60, stylize=c.visual.stylify_metatags) def state(repo_state): return _render("repo_state", repo_state) diff --git a/kallithea/templates/index_base.html b/kallithea/templates/index_base.html --- a/kallithea/templates/index_base.html +++ b/kallithea/templates/index_base.html @@ -59,11 +59,7 @@ - %if c.visual.stylify_metatags: - ${h.urlify_text(h.desc_stylize(gr.group_description))} - %else: - ${gr.group_description} - %endif + ${h.urlify_text(gr.group_description, stylize=c.visual.stylify_metatags)} ## this is commented out since for multi nested repos can be HEAVY! ## in number of executed queries during traversing uncomment at will ##${gr.repositories_recursive_count} diff --git a/kallithea/templates/summary/summary.html b/kallithea/templates/summary/summary.html --- a/kallithea/templates/summary/summary.html +++ b/kallithea/templates/summary/summary.html @@ -84,11 +84,7 @@ summary = lambda n:{False:'summary-short
- %if c.visual.stylify_metatags: -
${h.urlify_text(h.desc_stylize(h.html_escape(c.db_repo.description)))}
- %else: -
${h.urlify_text(h.html_escape(c.db_repo.description))}
- %endif +
${h.urlify_text(c.db_repo.description, stylize=c.visual.stylify_metatags)}
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 @@ -189,14 +189,14 @@ class TestLibs(BaseTestCase): "[requires => url] [lang => python] [just a tag]" "[,d] [ => ULR ] [obsolete] [desc]]" ) - from kallithea.lib.helpers import desc_stylize, html_escape - res = desc_stylize(html_escape(sample)) - self.assertTrue('
tag
' in res) - self.assertTrue('
obsolete
' in res) - self.assertTrue('
stale
' in res) - self.assertTrue('
python
' in res) - self.assertTrue('
requires => url
' in res) - self.assertTrue('
tag
' in res) + from kallithea.lib.helpers import urlify_text + res = urlify_text(sample, stylize=True) + self.assertIn('
tag
', res) + self.assertIn('
obsolete
', res) + self.assertIn('
stale
', res) + self.assertIn('
python
', res) + self.assertIn('
requires => url
', res) + self.assertIn('
tag
', res) def test_alternative_gravatar(self): from kallithea.lib.helpers import gravatar_url