#NEWLINE# def transformDataBlocks( doc , lines ) : #NEWLINE# #INDENT# inBlock = False #NEWLINE# blockTypes = { #NEWLINE# #INDENT# 'propdef' : transformPropdef , #NEWLINE# 'descdef' : transformDescdef , #NEWLINE# 'elementdef' : transformElementdef , #NEWLINE# 'argumentdef' : transformArgumentdef , #NEWLINE# 'railroad' : transformRailroad , #NEWLINE# 'biblio' : transformBiblio , #NEWLINE# 'anchors' : transformAnchors , #NEWLINE# 'link-defaults' : transformLinkDefaults , #NEWLINE# 'ignored-specs' : transformIgnoredSpecs , #NEWLINE# 'info' : transformInfo , #NEWLINE# 'include' : transformInclude , #NEWLINE# 'pre' : transformPre , #NEWLINE# #UNINDENT# } #NEWLINE# blockType = '' #NEWLINE# tagName = '' #NEWLINE# startLine = 0 #NEWLINE# newLines = [ ] #NEWLINE# for ( i , line ) in enumerate ( lines ) : #NEWLINE# #INDENT# match = re . match ( '\\s*<(pre|xmp)(.*)' , line , re . I ) #NEWLINE# if ( match and ( not inBlock ) ) : #NEWLINE# #INDENT# inBlock = True #NEWLINE# startLine = i #NEWLINE# tagName = match . group ( 1 ) #NEWLINE# typeMatch = re . search ( '|' . join ( blockTypes . keys ( ) ) , match . group ( 2 ) ) #NEWLINE# if typeMatch : #NEWLINE# #INDENT# blockType = typeMatch . group ( 0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# blockType = 'pre' #NEWLINE# #UNINDENT# #UNINDENT# match = re . match ( ( ( '(.*)</' + tagName ) + '>(.*)' ) , line , re . I ) #NEWLINE# if ( match and inBlock ) : #NEWLINE# #INDENT# inBlock = False #NEWLINE# if ( startLine == i ) : #NEWLINE# #INDENT# match = re . match ( '\\s*(<{0}[^>]*>)(.*)</{0}>(.*)' . format ( tagName ) , line , re . I ) #NEWLINE# repl = blockTypes [ blockType ] ( lines = [ match . group ( 2 ) ] , tagName = match , firstLine = match . group ( 1 ) , doc = doc ) #NEWLINE# newLines . extend ( repl ) #NEWLINE# newLines . append ( '<!--line count correction {0}-->' . format ( ( ( - len ( repl ) ) - 1 ) ) ) #NEWLINE# newLines . append ( match . group ( 3 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . match ( '^\\s*$' , match . group ( 1 ) ) : #NEWLINE# #INDENT# repl = blockTypes [ blockType ] ( lines = lines [ ( startLine + 1 ) : i ] , tagName = tagName , firstLine = lines [ startLine ] , doc = doc ) #NEWLINE# newLines . extend ( repl ) #NEWLINE# newLines . append ( '<!--line count correction {0}-->' . format ( ( ( ( i - startLine ) - len ( repl ) ) - 1 ) ) ) #NEWLINE# newLines . append ( match . group ( 2 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# repl = blockTypes [ blockType ] ( lines = ( lines [ ( startLine + 1 ) : i ] + [ match . group ( 1 ) ] ) , tagName = tagName , firstLine = lines [ startLine ] , doc = doc ) #NEWLINE# newLines . extend ( repl ) #NEWLINE# newLines . append ( '<!--line count correction {0}-->' . format ( ( ( ( i - startLine ) - len ( repl ) ) - 1 ) ) ) #NEWLINE# newLines . append ( match . group ( 2 ) ) #NEWLINE# #UNINDENT# #UNINDENT# tagName = '' #NEWLINE# blockType = '' #NEWLINE# continue #NEWLINE# #UNINDENT# if inBlock : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# newLines . append ( line ) #NEWLINE# #UNINDENT# return newLines