#NEWLINE# def format( self , soup ) : #NEWLINE# #INDENT# 'format a BeautifulSoup document\n\n        This will transform the block elements content from\n        multi-lines text into single line.\n\n        This allow us to avoid having to deal with further text\n        rendering once this step has been done.\n        ' #NEWLINE# for node in soup . findAll ( text = True ) : #NEWLINE# #INDENT# if node . rstrip ( ' ' ) . endswith ( '\n' ) : #NEWLINE# #INDENT# node . replaceWith ( node . rstrip ( ' ' ) . rstrip ( '\n' ) ) #NEWLINE# #UNINDENT# #UNINDENT# for tag in [ 'p' , 'li' ] : #NEWLINE# #INDENT# for node in soup . findAll ( tag ) : #NEWLINE# #INDENT# text = unicode ( node ) #NEWLINE# lines = [ x . strip ( ) for x in text . splitlines ( ) ] #NEWLINE# text = ' ' . join ( lines ) #NEWLINE# node . replaceWith ( BeautifulSoup . BeautifulSoup ( text ) ) #NEWLINE# #UNINDENT# #UNINDENT# soup = BeautifulSoup . BeautifulSoup ( unicode ( soup ) ) #NEWLINE# for node in soup . findAll ( 'br' ) : #NEWLINE# #INDENT# node . replaceWith ( '\n' ) #NEWLINE# #UNINDENT# soup = BeautifulSoup . BeautifulSoup ( unicode ( soup ) ) #NEWLINE# return soup