def cleanup_delete(chunks):
 while 1:
  try:
   (pre_delete, delete, post_delete) = split_delete(chunks)
  except NoDeletes:
   break
  (unbalanced_start, balanced, unbalanced_end) = split_unbalanced(delete)
  locate_unbalanced_start(unbalanced_start, pre_delete, post_delete)
  locate_unbalanced_end(unbalanced_end, pre_delete, post_delete)
  doc = pre_delete
  if (doc and (not doc[(-1)].endswith(' '))):
   doc[(-1)] += ' '
  doc.append('<del>')
  if (balanced and balanced[(-1)].endswith(' ')):
   balanced[(-1)] = balanced[(-1)][:(-1)]
  doc.extend(balanced)
  doc.append('</del> ')
  doc.extend(post_delete)
  chunks = doc
 return chunks

def cleanup_delete ( chunks ) : while 1 : try : ( pre_delete , delete , post_delete ) = split_delete ( chunks ) except NoDeletes : break ( unbalanced_start , balanced , unbalanced_end ) = split_unbalanced ( delete ) locate_unbalanced_start ( unbalanced_start , pre_delete , post_delete ) locate_unbalanced_end ( unbalanced_end , pre_delete , post_delete ) doc = pre_delete if ( doc and ( not doc [ ( - 1 ) ] . endswith ( ' ' ) ) ) : doc [ ( - 1 ) ] += ' ' doc . append ( '<del>' ) if ( balanced and balanced [ ( - 1 ) ] . endswith ( ' ' ) ) : balanced [ ( - 1 ) ] = balanced [ ( - 1 ) ] [ : ( - 1 ) ] doc . extend ( balanced ) doc . append ( '</del> ' ) doc . extend ( post_delete ) chunks = doc return chunks
cleans up any del_start/del_end markers in the document .