I'm writing software to track the changes an author made over several editions of a book. I already wrote code that produces a set of deltas describing differences between two editions.
Now I'm looking for an algorithm to combine all of these diffs inline to create a 'superstring' containing all of the text inserted and removed across every edition. Then I want to mark up the string in HTML with information about where the text was added and removed.
This way I can visualize the differences between the texts by simply applying different CSS attributes to the document.
Example
If the author changes a sentence in this way
-0- --1-- ---2--- ---3---
' ' -> 'cat' -> 'crate' -> 'crane'
My code produces these deltas
0-1) <insert 'cat' at 0>
1-2) <insert 'r' at 1> <insert 'e' at 3>
2-3) <remove from 3 to 4> <insert 'n' at 3>
Which I want to process to create a file like this:
<span class="inserted-1">c</span>
<span class="inserted-2">r</span>
<span class="inserted-1">a</span>
<span class="inserted-1 removed-3">t</span>
<span class="inserted-3">n</span>
<span class="inserted-2">e</span>
Question
What's the best algorithm to accomplish this task? Is there a name for this problem?