##// END OF EJS Templates
helpers: add @mentions to ordinary urlify_text and use urlify_text for render_w_mentions
Mads Kiilerich -
r6145:6944df7d default
parent child Browse files
Show More
@@ -1289,7 +1289,9 b' def urlify_text(s, repo_name=None, link_'
1289 Issues are linked to given issue-server.
1289 Issues are linked to given issue-server.
1290 If link_ is provided, all text not already linking somewhere will link there.
1290 If link_ is provided, all text not already linking somewhere will link there.
1291 """
1291 """
1292 if truncate is not None:
1292 if truncate is None:
1293 s = s.rstrip()
1294 else:
1293 s = truncatef(s, truncate, whole_word=True)
1295 s = truncatef(s, truncate, whole_word=True)
1294 s = html_escape(s)
1296 s = html_escape(s)
1295 if repo_name is not None:
1297 if repo_name is not None:
@@ -1299,6 +1301,7 b' def urlify_text(s, repo_name=None, link_'
1299 s = _urlify_text(s)
1301 s = _urlify_text(s)
1300 if repo_name is not None:
1302 if repo_name is not None:
1301 s = urlify_issues(s, repo_name, link_)
1303 s = urlify_issues(s, repo_name, link_)
1304 s = MENTIONS_REGEX.sub(_mentions_replace, s)
1302 return literal(s)
1305 return literal(s)
1303
1306
1304
1307
@@ -1411,17 +1414,8 b' def render_w_mentions(source, repo_name='
1411 Render plain text with revision hashes and issue references urlified
1414 Render plain text with revision hashes and issue references urlified
1412 and with @mention highlighting.
1415 and with @mention highlighting.
1413 """
1416 """
1414 s = source.rstrip()
1417 s = safe_unicode(source)
1415 s = safe_unicode(s)
1418 s = urlify_text(s, repo_name=repo_name)
1416 s = '\n'.join(s.splitlines())
1417 s = html_escape(s)
1418 # this sequence of html-ifications seems to be safe and non-conflicting
1419 # if the issues regexp is sane
1420 s = _urlify_text(s)
1421 if repo_name is not None:
1422 s = urlify_changesets(s, repo_name)
1423 s = urlify_issues(s, repo_name)
1424 s = MENTIONS_REGEX.sub(_mentions_replace, s)
1425 return literal('<div class="formatted-fixed">%s</div>' % s)
1419 return literal('<div class="formatted-fixed">%s</div>' % s)
1426
1420
1427
1421
@@ -311,8 +311,7 b' class TestLibs(TestController):'
311 """Multi line\n"""
311 """Multi line\n"""
312 """ url[123123123123]\n"""
312 """ url[123123123123]\n"""
313 """ some text url[123123123123]\n"""
313 """ some text url[123123123123]\n"""
314 """ sometimes !\n"""
314 """ sometimes !"""),
315 """ """),
316 ])
315 ])
317 def test_urlify_changesets(self, sample, expected):
316 def test_urlify_changesets(self, sample, expected):
318 def fake_url(self, *args, **kwargs):
317 def fake_url(self, *args, **kwargs):
@@ -348,7 +347,7 b' class TestLibs(TestController):'
348 """ some text lalala""",
347 """ some text lalala""",
349 "https://foo.bar.example.com"),
348 "https://foo.bar.example.com"),
350 ("@mention @someone",
349 ("@mention @someone",
351 """@mention @someone""",
350 """<b>@mention</b> <b>@someone</b>""",
352 ""),
351 ""),
353 ("deadbeefcafe 123412341234",
352 ("deadbeefcafe 123412341234",
354 """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a> <a class="revision-link" href="/repo_name/changeset/123412341234">123412341234</a>""",
353 """<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 b' class TestLibs(TestController):'
365 ("deadbeefcafe @mention, and http://foo.bar/ yo",
364 ("deadbeefcafe @mention, and http://foo.bar/ yo",
366 """<a class="message-link" href="#the-link"></a>"""
365 """<a class="message-link" href="#the-link"></a>"""
367 """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a>"""
366 """<a class="revision-link" href="/repo_name/changeset/deadbeefcafe">deadbeefcafe</a>"""
368 """<a class="message-link" href="#the-link"> @mention, and </a>"""
367 """<a class="message-link" href="#the-link"> <b>@mention</b>, and </a>"""
369 """<a href="http://foo.bar/">http://foo.bar/</a>"""
368 """<a href="http://foo.bar/">http://foo.bar/</a>"""
370 """<a class="message-link" href="#the-link"> yo</a>"""),
369 """<a class="message-link" href="#the-link"> yo</a>"""),
371 ])
370 ])
General Comments 0
You need to be logged in to leave comments. Login now