<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import unicode_literals <EOL> from . import Extension <EOL> from . . blockprocessors import BlockProcessor <EOL> from . . import util <EOL> import re <EOL> extensions = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> class ExtraExtension ( Extension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . config = kwargs . pop ( '<STR_LIT>' , { } ) <EOL> self . config . update ( kwargs ) <EOL> def extendMarkdown ( self , md , md_globals ) : <EOL> """<STR_LIT>""" <EOL> md . registerExtensions ( extensions , self . config ) <EOL> if not md . safeMode : <EOL> md . preprocessors [ '<STR_LIT>' ] . markdown_in_raw = True <EOL> md . parser . blockprocessors . add ( '<STR_LIT>' , <EOL> MarkdownInHtmlProcessor ( md . parser ) , <EOL> '<STR_LIT>' ) <EOL> md . parser . blockprocessors . tag_counter = - <NUM_LIT:1> <EOL> md . parser . blockprocessors . contain_span_tags = re . compile ( <EOL> r'<STR_LIT>' , re . IGNORECASE ) <EOL> def makeExtension ( * args , ** kwargs ) : <EOL> return ExtraExtension ( * args , ** kwargs ) <EOL> class MarkdownInHtmlProcessor ( BlockProcessor ) : <EOL> """<STR_LIT>""" <EOL> def test ( self , parent , block ) : <EOL> return block == util . TAG_PLACEHOLDER % str ( self . parser . blockprocessors . tag_counter + <NUM_LIT:1> ) <EOL> def _process_nests ( self , element , block ) : <EOL> """<STR_LIT>""" <EOL> nest_index = [ ] <EOL> i = self . parser . blockprocessors . tag_counter + <NUM_LIT:1> <EOL> while len ( self . _tag_data ) > i and self . _tag_data [ i ] [ '<STR_LIT>' ] : <EOL> left_child_index = self . _tag_data [ i ] [ '<STR_LIT>' ] <EOL> right_child_index = self . _tag_data [ i ] [ '<STR_LIT>' ] <EOL> nest_index . append ( ( left_child_index - <NUM_LIT:1> , right_child_index ) ) <EOL> i += <NUM_LIT:1> <EOL> for i , ( left_index , right_index ) in enumerate ( nest_index [ : - <NUM_LIT:1> ] ) : <EOL> self . run ( element , block [ left_index : right_index ] , <EOL> block [ right_index : nest_index [ i + <NUM_LIT:1> ] [ <NUM_LIT:0> ] ] , True ) <EOL> self . run ( element , block [ nest_index [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] : nest_index [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] ] , <EOL> block [ nest_index [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] : ] , True ) <EOL> def run ( self , parent , blocks , tail = None , nest = False ) : <EOL> self . _tag_data = self . parser . markdown . htmlStash . tag_data <EOL> self . parser . blockprocessors . tag_counter += <NUM_LIT:1> <EOL> tag = self . _tag_data [ self . parser . blockprocessors . tag_counter ] <EOL> markdown_value = tag [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> element = util . etree . SubElement ( parent , tag [ '<STR_LIT>' ] , tag [ '<STR_LIT>' ] ) <EOL> if nest : <EOL> self . parser . parseBlocks ( parent , tail ) <EOL> block = blocks [ <NUM_LIT:1> : ] <EOL> else : <EOL> block = blocks [ tag [ '<STR_LIT>' ] + <NUM_LIT:1> : tag [ '<STR_LIT>' ] ] <EOL> del blocks [ : tag [ '<STR_LIT>' ] ] <EOL> if ( self . parser . blockprocessors . contain_span_tags . match ( <EOL> tag [ '<STR_LIT>' ] ) and markdown_value != '<STR_LIT>' ) or markdown_value == '<STR_LIT>' : <EOL> element . text = '<STR_LIT:\n>' . join ( block ) <EOL> else : <EOL> i = self . parser . blockprocessors . tag_counter + <NUM_LIT:1> <EOL> if len ( self . _tag_data ) > i and self . _tag_data [ i ] [ '<STR_LIT>' ] : <EOL> first_subelement_index = self . _tag_data [ i ] [ '<STR_LIT>' ] - <NUM_LIT:1> <EOL> self . parser . parseBlocks ( <EOL> element , block [ : first_subelement_index ] ) <EOL> if not nest : <EOL> block = self . _process_nests ( element , block ) <EOL> else : <EOL> self . parser . parseBlocks ( element , block ) </s>
