<s> from __future__ import unicode_literals <EOL> import re <EOL> import copy <EOL> from django . conf import settings <EOL> from django . contrib . auth import get_user_model <EOL> import mistune <EOL> from . utils . emoji import emojis <EOL> User = get_user_model ( ) <EOL> _linebreak = re . compile ( r'<STR_LIT>' ) <EOL> _text = re . compile ( <EOL> r'<STR_LIT>' <EOL> ) <EOL> class InlineGrammar ( mistune . InlineGrammar ) : <EOL> emoji = re . compile ( <EOL> r'<STR_LIT>' <EOL> ) <EOL> mention = re . compile ( <EOL> r'<STR_LIT>' , <EOL> flags = re . UNICODE <EOL> ) <EOL> def hard_wrap ( self ) : <EOL> self . linebreak = _linebreak <EOL> self . text = _text <EOL> class InlineLexer ( mistune . InlineLexer ) : <EOL> default_rules = copy . copy ( mistune . InlineLexer . default_rules ) <EOL> default_rules . insert ( <NUM_LIT:2> , '<STR_LIT>' ) <EOL> default_rules . insert ( <NUM_LIT:2> , '<STR_LIT>' ) <EOL> def __init__ ( self , renderer , rules = None , ** kwargs ) : <EOL> rules = InlineGrammar ( ) <EOL> rules . hard_wrap ( ) <EOL> super ( InlineLexer , self ) . __init__ ( renderer , rules , ** kwargs ) <EOL> self . mentions = { } <EOL> self . _mention_count = <NUM_LIT:0> <EOL> def output_emoji ( self , m ) : <EOL> emoji = m . group ( '<STR_LIT>' ) <EOL> if emoji not in emojis : <EOL> return m . group ( <NUM_LIT:0> ) <EOL> name_raw = emoji <EOL> name_class = emoji . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) . replace ( '<STR_LIT:+>' , '<STR_LIT>' ) <EOL> return self . renderer . emoji ( name_class = name_class , name_raw = name_raw ) <EOL> def output_mention ( self , m ) : <EOL> username = m . group ( '<STR_LIT:username>' ) <EOL> if username in self . mentions : <EOL> user = self . mentions [ username ] <EOL> return self . renderer . mention ( username , user . st . get_absolute_url ( ) ) <EOL> if self . _mention_count >= settings . ST_MENTIONS_PER_COMMENT : <EOL> return m . group ( <NUM_LIT:0> ) <EOL> self . _mention_count += <NUM_LIT:1> <EOL> try : <EOL> user = User . objects . select_related ( '<STR_LIT>' ) . get ( username = username ) <EOL> except User . DoesNotExist : <EOL> return m . group ( <NUM_LIT:0> ) <EOL> self . mentions [ username ] = user <EOL> return self . renderer . mention ( username , user . st . get_absolute_url ( ) ) </s>
