<s> """<STR_LIT>""" <EOL> import re <EOL> import util <EOL> import odict <EOL> def build_postprocessors ( md_instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> postprocessors = odict . OrderedDict ( ) <EOL> postprocessors [ "<STR_LIT>" ] = RawHtmlPostprocessor ( md_instance ) <EOL> postprocessors [ "<STR_LIT>" ] = AndSubstitutePostprocessor ( ) <EOL> postprocessors [ "<STR_LIT>" ] = UnescapePostprocessor ( ) <EOL> return postprocessors <EOL> class Postprocessor ( util . Processor ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , text ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class RawHtmlPostprocessor ( Postprocessor ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , text ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( self . markdown . htmlStash . html_counter ) : <EOL> html , safe = self . markdown . htmlStash . rawHtmlBlocks [ i ] <EOL> if self . markdown . safeMode and not safe : <EOL> if str ( self . markdown . safeMode ) . lower ( ) == '<STR_LIT>' : <EOL> html = self . escape ( html ) <EOL> elif str ( self . markdown . safeMode ) . lower ( ) == '<STR_LIT>' : <EOL> html = '<STR_LIT>' <EOL> else : <EOL> html = self . markdown . html_replacement_text <EOL> if self . isblocklevel ( html ) and ( safe or not self . markdown . safeMode ) : <EOL> text = text . replace ( "<STR_LIT>" % <EOL> ( self . markdown . htmlStash . get_placeholder ( i ) ) , <EOL> html + "<STR_LIT:\n>" ) <EOL> text = text . replace ( self . markdown . htmlStash . get_placeholder ( i ) , <EOL> html ) <EOL> return text <EOL> def escape ( self , html ) : <EOL> """<STR_LIT>""" <EOL> html = html . replace ( '<STR_LIT:&>' , '<STR_LIT>' ) <EOL> html = html . replace ( '<STR_LIT:<>' , '<STR_LIT>' ) <EOL> html = html . replace ( '<STR_LIT:>>' , '<STR_LIT>' ) <EOL> return html . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> def isblocklevel ( self , html ) : <EOL> m = re . match ( r'<STR_LIT>' , html ) <EOL> if m : <EOL> if m . group ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] in ( '<STR_LIT:!>' , '<STR_LIT:?>' , '<STR_LIT:@>' , '<STR_LIT:%>' ) : <EOL> return True <EOL> return util . isBlockLevel ( m . group ( <NUM_LIT:1> ) ) <EOL> return False <EOL> class AndSubstitutePostprocessor ( Postprocessor ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , text ) : <EOL> text = text . replace ( util . AMP_SUBSTITUTE , "<STR_LIT:&>" ) <EOL> return text <EOL> class UnescapePostprocessor ( Postprocessor ) : <EOL> """<STR_LIT>""" <EOL> RE = re . compile ( '<STR_LIT>' % ( util . STX , util . ETX ) ) <EOL> def unescape ( self , m ) : <EOL> return unichr ( int ( m . group ( <NUM_LIT:1> ) ) ) <EOL> def run ( self , text ) : <EOL> return self . RE . sub ( self . unescape , text ) </s>
