Mercurial > kallithea
changeset 6186:24632b87a263
helpers: inline @mention markup in urlify_text
MENTIONS_REGEX is already compiled.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | 26648b25473d |
children | 923db690b56f |
files | kallithea/lib/helpers.py kallithea/lib/markup_renderer.py |
diffstat | 2 files changed, 7 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/helpers.py Tue Sep 06 00:51:18 2016 +0200 @@ -1248,13 +1248,15 @@ _URLIFY_RE = re.compile(r''' # URL markup (?P<url>%s) | +# @mention markup +(?P<mention>%s) | # "Stylize" markup \[see\ \=>\ *(?P<seen>[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | \[license\ \=>\ *(?P<license>[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | \[(?P<tagtype>requires|recommends|conflicts|base)\ \=>\ *(?P<tagvalue>[a-zA-Z0-9\-\/]*)\] | \[(?:lang|language)\ \=>\ *(?P<lang>[a-zA-Z\-\/\#\+]*)\] | \[(?P<tag>[a-z]+)\] -''' % (url_re.pattern), +''' % (url_re.pattern, MENTIONS_REGEX.pattern), re.VERBOSE | re.MULTILINE | re.IGNORECASE) @@ -1273,6 +1275,9 @@ url = match_obj.group('url') if url is not None: return '<a href="%(url)s">%(url)s</a>' % {'url': url} + mention = match_obj.group('mention') + if mention is not None: + return '<b>%s</b>' % mention if stylize: seen = match_obj.group('seen') if seen: @@ -1308,7 +1313,6 @@ s = _urlify(s) if repo_name is not None: s = urlify_issues(s, repo_name, link_) - s = MENTIONS_REGEX.sub(_mentions_replace, s) s = s.replace('\r\n', '<br/>').replace('\n', '<br/>') return literal(s) @@ -1413,10 +1417,6 @@ return newtext -def _mentions_replace(match_obj): - return '<b>@%s</b>' % match_obj.group(1) - - def render_w_mentions(source, repo_name=None): """ Render plain text with revision hashes and issue references urlified
--- a/kallithea/lib/markup_renderer.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/markup_renderer.py Tue Sep 06 00:51:18 2016 +0200 @@ -190,10 +190,9 @@ @classmethod def rst_with_mentions(cls, source): - mention_pat = re.compile(MENTIONS_REGEX) def wrapp(match_obj): uname = match_obj.groups()[0] return '\ **@%(uname)s**\ ' % {'uname': uname} - mention_hl = mention_pat.sub(wrapp, source).strip() + mention_hl = MENTIONS_REGEX.sub(wrapp, source).strip() return cls.rst(mention_hl)