Skip to content

Instantly share code, notes, and snippets.

@StreetStrider
Forked from ximing/diff.js
Created April 7, 2026 09:39
Show Gist options
  • Select an option

  • Save StreetStrider/53557752391e57102a1031f2ba3164de to your computer and use it in GitHub Desktop.

Select an option

Save StreetStrider/53557752391e57102a1031f2ba3164de to your computer and use it in GitHub Desktop.
quill diff
function findDiff() {
var oldContent = quill_old.getContents();
var newContent = quill_new.getContents();
var diff = oldContent.diff(newContent);
// console.log('old', oldContent);
// console.log('new', newContent);
for (var i = 0; i < diff.ops.length; i++) {
var op = diff.ops[i];
// if the change was an insertion
if (op.hasOwnProperty('insert')) {
// color it green
op.attributes = {
background: "#cce8cc",
color: "#003700"
};
}
// if the change was a deletion
if (op.hasOwnProperty('delete')) {
// keep the text
op.retain = op.delete;
delete op.delete;
// but color it red and struckthrough
op.attributes = {
background: "#e8cccc",
color: "#370000",
strike: true
};
}
}
// console.log('diff', diff);
var adjusted = oldContent.compose(diff);
// console.log('adjusted', adjusted);
// profit!
quill_diff.setContents(adjusted);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment