I am trying to use two different textarea
s displaying the same code, but with one master, and another copy. In the copy textarea
, I would like to highlight changes, something similar to what GitHub offers when we do some changes.
I was wondering if this is possible or if someone did something similar before. Any advice is welcome.
The CodeMirror Merge add-on is exactly what you want. See the demo, which matches your description.
At first I thought you wanted a separate diff, displayed in a div
below your textarea
s rather than inside one of the textarea
s, and I wrote the following answer. It may still be useful.
Check out the google-diff-match-patch library, used by the CodeMirror Merge add-on. It’s not a drop-in solution, but it looks like you could use
diff_main
to get a list of original and changed text, and then display that yourself. The library also providesdiff_prettyHtml
, which outputs example markup for the diff.