<s> import markdown <EOL> class State ( list ) : <EOL> """<STR_LIT>""" <EOL> def set ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . append ( state ) <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . pop ( ) <EOL> def isstate ( self , state ) : <EOL> """<STR_LIT>""" <EOL> if len ( self ) : <EOL> return self [ - <NUM_LIT:1> ] == state <EOL> else : <EOL> return False <EOL> class BlockParser : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . blockprocessors = markdown . odict . OrderedDict ( ) <EOL> self . state = State ( ) <EOL> def parseDocument ( self , lines ) : <EOL> """<STR_LIT>""" <EOL> self . root = markdown . etree . Element ( markdown . DOC_TAG ) <EOL> self . parseChunk ( self . root , '<STR_LIT:\n>' . join ( lines ) ) <EOL> return markdown . etree . ElementTree ( self . root ) <EOL> def parseChunk ( self , parent , text ) : <EOL> """<STR_LIT>""" <EOL> self . parseBlocks ( parent , text . split ( '<STR_LIT>' ) ) <EOL> def parseBlocks ( self , parent , blocks ) : <EOL> """<STR_LIT>""" <EOL> while blocks : <EOL> for processor in self . blockprocessors . values ( ) : <EOL> if processor . test ( parent , blocks [ <NUM_LIT:0> ] ) : <EOL> processor . run ( parent , blocks ) <EOL> break </s>
