def regularise_html(html):
 if (html is None):
  return
 html = re.sub('\n', ' ', html)
 matches = re.findall('(<[^>]*>|%[^%]\\([^)]*\\)\\w|[^<%]+|%)', html)
 for i in xrange(len(matches)):
  match = matches[i]
  if (match.startswith('<') or match.startswith('%')):
   continue
  matches[i] = re.sub('\\s{2,}', ' ', match)
 html = ''.join(matches)
 return html

def regularise_html ( html ) : if ( html is None ) : return html = re . sub ( '\n' , ' ' , html ) matches = re . findall ( '(<[^>]*>|%[^%]\\([^)]*\\)\\w|[^<%]+|%)' , html ) for i in xrange ( len ( matches ) ) : match = matches [ i ] if ( match . startswith ( '<' ) or match . startswith ( '%' ) ) : continue matches [ i ] = re . sub ( '\\s{2,}' , ' ' , match ) html = '' . join ( matches ) return html
take badly formatted html with strings etc and make it beautiful generally remove surlus whitespace and kill this will break <code><pre> tags but they should not be being translated .