def flatten_el(el, include_hrefs, skip_tag=False):
 if (not skip_tag):
  if (el.tag == 'img'):
   (yield ('img', el.get('src'), start_tag(el)))
  else:
   (yield start_tag(el))
 if ((el.tag in empty_tags) and (not el.text) and (not len(el)) and (not el.tail)):
  return
 start_words = split_words(el.text)
 for word in start_words:
  (yield html_escape(word))
 for child in el:
  for item in flatten_el(child, include_hrefs=include_hrefs):
   (yield item)
 if ((el.tag == 'a') and el.get('href') and include_hrefs):
  (yield ('href', el.get('href')))
 if (not skip_tag):
  (yield end_tag(el))
  end_words = split_words(el.tail)
  for word in end_words:
   (yield html_escape(word))

def flatten_el ( el , include_hrefs , skip_tag = False ) : if ( not skip_tag ) : if ( el . tag == 'img' ) : ( yield ( 'img' , el . get ( 'src' ) , start_tag ( el ) ) ) else : ( yield start_tag ( el ) ) if ( ( el . tag in empty_tags ) and ( not el . text ) and ( not len ( el ) ) and ( not el . tail ) ) : return start_words = split_words ( el . text ) for word in start_words : ( yield html_escape ( word ) ) for child in el : for item in flatten_el ( child , include_hrefs = include_hrefs ) : ( yield item ) if ( ( el . tag == 'a' ) and el . get ( 'href' ) and include_hrefs ) : ( yield ( 'href' , el . get ( 'href' ) ) ) if ( not skip_tag ) : ( yield end_tag ( el ) ) end_words = split_words ( el . tail ) for word in end_words : ( yield html_escape ( word ) )
takes an lxml element el .