You can use this code with a small changes:
(this code format each same and not same strings)
import Levenshtein
style_same = "style=\"background: green;\""
style_unsame = "style=\"background: red;\""
f_str = '<span {style}>{text}</span>'
def getFormattedDiff(astring, bstring):
formatted_a = []
formatted_b = []
begina, beginb = 0, 0
for matching_block in Levenshtein.matching_blocks(Levenshtein.opcodes(astring, bstring), astring, bstring):
a, b, size = matching_block.a, matching_block.b, matching_block.size
formatted_a.append(f_str.format(style=style_unsame, text = astring[begina:a]) + f_str.format(style=style_same, text = astring[a:a+size]))
formatted_b.append(f_str.format(style=style_unsame, text = bstring[beginb:b]) + f_str.format(style=style_same, text = bstring[b:b+size]))
begina, beginb = a+size, b+size
formatted_a.append(f_str.format(style=style_unsame, text = astring[begina:]))
formatted_b.append(f_str.format(style=style_unsame, text = bstring[beginb:]))
return ''.join(formatted_a), ''.join(formatted_b)
'XX'
)? You're just looking for positional differences right? this means,s1[0]
withs2[0]
,s1[1]
withs2[1]
and so on .. – Pierette