# HG changeset patch # User Mads Kiilerich # Date 2014-07-04 14:12:07 # Node ID b97ba9b237964414cf4ca41bc6c7214062583221 # Parent 072175b07608a0ad15fa95559f7662fe7e950697 helpers: introduce render_w_mentions Eventually this function should support and auto detect multiple formats and is thus not named for a specific format. But for now it is plain text only. This kind of markup can quite easily and safely support additional magic markup. It is much harder to do that on top of a richer markup format; it must essentially be done in a single pass, with both all the various regexps and the rst formatting done in a single pass. diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -55,7 +55,7 @@ from kallithea.lib.annotate import annot from kallithea.lib.utils import repo_name_slug, get_custom_lexer from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \ get_changeset_safe, datetime_to_time, time_to_datetime, AttributeDict, \ - safe_int + safe_int, MENTIONS_REGEX from kallithea.lib.markup_renderer import MarkupRenderer, url_re from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset @@ -1397,6 +1397,26 @@ def rst_w_mentions(source): return literal('
%s
' % MarkupRenderer.rst_with_mentions(source)) + +def mentions_replace(match_obj): + return '@%s' % match_obj.group(1) + + +def render_w_mentions(source): + """ + Render plain text 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) + s = MENTIONS_REGEX.sub(mentions_replace, s) + return literal('%s' % s) + + def short_ref(ref_type, ref_name): if ref_type == 'rev': return short_id(ref_name)