Changeset - 6944df7de4e1
[Not reviewed]
default
0 2 0
Mads Kiilerich - 9 years ago 2016-09-06 00:51:18
madski@unity3d.com
helpers: add @mentions to ordinary urlify_text and use urlify_text for render_w_mentions
2 files changed with 9 insertions and 16 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -1289,7 +1289,9 @@ def urlify_text(s, repo_name=None, link_
 
    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 @@ def urlify_text(s, repo_name=None, link_
 
    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 @@ def render_w_mentions(source, repo_name=
 
    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)
 

	
 

	
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -311,8 +311,7 @@ class TestLibs(TestController):
 
       """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 @@ class TestLibs(TestController):
 
       """       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 @@ class TestLibs(TestController):
 
      ("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>"""),
 
    ])
0 comments (0 inline, 0 general)