8
def _replace(old, new):
9
return "~~%s~~'''%s'''" % (old, new)
11
def _delete(old, new):
14
def _insert(old, new):
15
return "'''%s'''" % new
17
def diff2wiki(old, new):
18
"""Create a wiki formatting for the diff of two strings.
19
>>> old = "I think I want spam."
20
>>> new = "I don't want spam!"
21
>>> diff2wiki(old, new)
22
"I '''don''''t~~hink I~~ want spam~~.~~'''!'''"
24
s = difflib.SequenceMatcher(None, old, new)
25
result = [globals()["_%s" % tag](old[i1:i2], new[j1:j2])
26
for tag, i1, i2, j1, j2 in s.get_opcodes()]
27
return "".join(result)
29
if __name__ == "__main__":
30
if len(sys.argv) != 3:
31
print 'diff2wiki "Old text" "New text"'
33
print diff2wiki(*sys.argv[1:])