def show_diff(seqm):
 output = []
 insert_el = '<span style="background:#4AA02C; font-size:1.5em; ">'
 ins_el_close = '</span>'
 del_el = '<span style="background:#D16587; font-size:1.5em;">'
 del_el_close = '</span>'
 for (opcode, a0, a1, b0, b1) in seqm.get_opcodes():
  content_a = strip_html(seqm.a[a0:a1])
  content_b = strip_html(seqm.b[b0:b1])
  if (opcode == 'equal'):
   output.append(content_a)
  elif (opcode == 'insert'):
   output.append(((insert_el + content_b) + ins_el_close))
  elif (opcode == 'delete'):
   output.append(((del_el + content_a) + del_el_close))
  elif (opcode == 'replace'):
   output.append((((((del_el + content_a) + del_el_close) + insert_el) + content_b) + ins_el_close))
  else:
   raise RuntimeError('unexpected opcode')
 return ''.join(output)

def show_diff ( seqm ) : output = [ ] insert_el = '<span style="background:#4AA02C; font-size:1.5em; ">' ins_el_close = '</span>' del_el = '<span style="background:#D16587; font-size:1.5em;">' del_el_close = '</span>' for ( opcode , a0 , a1 , b0 , b1 ) in seqm . get_opcodes ( ) : content_a = strip_html ( seqm . a [ a0 : a1 ] ) content_b = strip_html ( seqm . b [ b0 : b1 ] ) if ( opcode == 'equal' ) : output . append ( content_a ) elif ( opcode == 'insert' ) : output . append ( ( ( insert_el + content_b ) + ins_el_close ) ) elif ( opcode == 'delete' ) : output . append ( ( ( del_el + content_a ) + del_el_close ) ) elif ( opcode == 'replace' ) : output . append ( ( ( ( ( ( del_el + content_a ) + del_el_close ) + insert_el ) + content_b ) + ins_el_close ) ) else : raise RuntimeError ( 'unexpected opcode' ) return '' . join ( output )
unify operations between two compared strings seqm is a difflib .