jsdifflib icon indicating copy to clipboard operation
jsdifflib copied to clipboard

Ignore whitespaces

Open suther opened this issue 10 years ago • 1 comments

Please make an option to ignore whitespaces and tabs

suther avatar Oct 08 '15 11:10 suther

@suther You may remove whitespaces before calling difflib.SequenceMatcher - with this function you can remove trailing whitespaces:

removeTrailingWhitespace = function(txt) {
    var pattern = /\s*$/g;
    var newtxt = [];
    for(var i=0;i<txt.length;i++) {
        newtxt.push(txt[i].replace(pattern, ''));
    }
    return newtxt;
}

var base = removeTrailingWhitespace( difflib.stringAsLines(basetxt) );
var new = removeTrailingWhitespace( difflib.stringAsLines(newtxt) );

var sm = new difflib.SequenceMatcher(base, new);
(...)

tbrugz avatar Apr 12 '16 21:04 tbrugz