# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID 24632b87a2635027dd4ba3bcbdb13a5e89436181 # Parent 26648b25473d1686823c15cc6b6e3d33680ac402 helpers: inline @mention markup in urlify_text MENTIONS_REGEX is already compiled. diff -r 26648b25473d -r 24632b87a263 kallithea/lib/helpers.py --- 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%s) | +# @mention markup +(?P%s) | # "Stylize" markup \[see\ \=>\ *(?P[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | \[license\ \=>\ *(?P[a-zA-Z0-9\/\=\?\&\ \:\/\.\-]*)\] | \[(?Prequires|recommends|conflicts|base)\ \=>\ *(?P[a-zA-Z0-9\-\/]*)\] | \[(?:lang|language)\ \=>\ *(?P[a-zA-Z\-\/\#\+]*)\] | \[(?P[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 '%(url)s' % {'url': url} + mention = match_obj.group('mention') + if mention is not None: + return '%s' % 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', '
').replace('\n', '
') return literal(s) @@ -1413,10 +1417,6 @@ return newtext -def _mentions_replace(match_obj): - return '@%s' % match_obj.group(1) - - def render_w_mentions(source, repo_name=None): """ Render plain text with revision hashes and issue references urlified diff -r 26648b25473d -r 24632b87a263 kallithea/lib/markup_renderer.py --- 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)