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.
Mergely is another option that produces very nice visual diffs using CodeMirror and is distributed under the GPL, LGPL and MPL licenses. It's GitHub repo is here.
Also Prettydiff which isn't very pretty, but when you click the "execute" button at the bottom you get an interesting visual diff. Not sure if the diff itself is using codemirror or just the two input texts that the diff is generated from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With