#NEWLINE# def run( self , doc ) : #NEWLINE# #INDENT# for elem in doc . getiterator ( ) : #NEWLINE# #INDENT# if isBlockLevel ( elem . tag ) : #NEWLINE# #INDENT# RE = self . BLOCK_RE #NEWLINE# if isheader ( elem ) : #NEWLINE# #INDENT# RE = elem . HEADER_RE #NEWLINE# #UNINDENT# if ( len ( elem ) and elem [ ( - 1 ) ] . tail ) : #NEWLINE# #INDENT# m = RE . search ( elem [ ( - 1 ) ] . tail ) #NEWLINE# if m : #NEWLINE# #INDENT# self . assign_attrs ( elem , m . group ( 1 ) ) #NEWLINE# elem [ ( - 1 ) ] . tail = elem [ ( - 1 ) ] . tail [ : m . start ( ) ] #NEWLINE# if isheader ( elem ) : #NEWLINE# #INDENT# elem [ ( - 1 ) ] . tail = elem [ ( - 1 ) ] . tail . rstrip ( '#' ) . rstrip ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if elem . text : #NEWLINE# #INDENT# m = RE . search ( elem . text ) #NEWLINE# if m : #NEWLINE# #INDENT# self . assign_attrs ( elem , m . group ( 1 ) ) #NEWLINE# elem . text = elem . text [ : m . start ( ) ] #NEWLINE# if isheader ( elem ) : #NEWLINE# #INDENT# elem . text = elem . text . rstrip ( '#' ) . rstrip ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if elem . tail : #NEWLINE# #INDENT# m = self . INLINE_RE . match ( elem . tail ) #NEWLINE# if m : #NEWLINE# #INDENT# self . assign_attrs ( elem , m . group ( 1 ) ) #NEWLINE# elem . tail = elem . tail [ m . end ( ) : ]