Skip to content

Instantly share code, notes, and snippets.

@dirk
Created November 27, 2008 14:58
Show Gist options
  • Save dirk/29764 to your computer and use it in GitHub Desktop.
Save dirk/29764 to your computer and use it in GitHub Desktop.
require 'diff-0.4/lib/algorithm/diff'
a = 'testing
sled
123
testing'
ab = a.dup
b = 'testing
sledding across the white snow
123error
testing'
diff = Diff.diff(a, b)
offset = 0
b_insert = '<b>'
a_insert = '</b>'
diff.each do |d|
a.insert(d[1] + offset, b_insert + d[2])
offset += b_insert.length
a.insert(d[1] + d[2].length + offset, a_insert)
offset += a_insert.length
end
puts "\nOriginal:"
puts ab
puts "\nChanged:"
puts a, "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment