Clean code and force code style
Since more people are contributing to the code Codacy will help keep it consistent and easy to maintain, by suggesting improvements
This commit is contained in:
parent
4d3d752361
commit
8d86a15d69
11 changed files with 546 additions and 468 deletions
344
dist/diff2html.js
vendored
344
dist/diff2html.js
vendored
|
|
@ -51,7 +51,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = __webpack_require__(1).DiffParser;
|
var diffParser = __webpack_require__(1).DiffParser;
|
||||||
var fileLister = __webpack_require__(3).FileListPrinter;
|
var fileLister = __webpack_require__(3).FileListPrinter;
|
||||||
|
|
@ -63,9 +63,9 @@
|
||||||
/*
|
/*
|
||||||
* Line diff type configuration
|
* Line diff type configuration
|
||||||
var config = {
|
var config = {
|
||||||
"wordByWord": true, // (default)
|
'wordByWord': true, // (default)
|
||||||
// OR
|
// OR
|
||||||
"charByChar": true
|
'charByChar': true
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -87,19 +87,19 @@
|
||||||
diffJson = diffParser.generateDiffJson(diffInput);
|
diffJson = diffParser.generateDiffJson(diffInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileList = "";
|
var fileList = '';
|
||||||
if (configOrEmpty.showFiles === true) {
|
if (configOrEmpty.showFiles === true) {
|
||||||
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
|
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
var diffOutput = "";
|
var diffOutput = '';
|
||||||
if (configOrEmpty.outputFormat === 'side-by-side') {
|
if (configOrEmpty.outputFormat === 'side-by-side') {
|
||||||
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
||||||
} else {
|
} else {
|
||||||
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileList + diffOutput
|
return fileList + diffOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -112,9 +112,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'diff';
|
configOrEmpty.inputFormat = 'diff';
|
||||||
configOrEmpty['outputFormat'] = 'line-by-line';
|
configOrEmpty.outputFormat = 'line-by-line';
|
||||||
return this.getPrettyHtml(diffInput, configOrEmpty)
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -122,9 +122,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'json';
|
configOrEmpty.inputFormat = 'json';
|
||||||
configOrEmpty['outputFormat'] = 'line-by-line';
|
configOrEmpty.outputFormat = 'line-by-line';
|
||||||
return this.getPrettyHtml(diffJson, configOrEmpty)
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -132,9 +132,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'diff';
|
configOrEmpty.inputFormat = 'diff';
|
||||||
configOrEmpty['outputFormat'] = 'side-by-side';
|
configOrEmpty.outputFormat = 'side-by-side';
|
||||||
return this.getPrettyHtml(diffInput, configOrEmpty)
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -142,18 +142,18 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'json';
|
configOrEmpty.inputFormat = 'json';
|
||||||
configOrEmpty['outputFormat'] = 'side-by-side';
|
configOrEmpty.outputFormat = 'side-by-side';
|
||||||
return this.getPrettyHtml(diffJson, configOrEmpty)
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
var diffName = 'Diff2Html';
|
|
||||||
var diffObject = new Diff2Html();
|
var diffObject = new Diff2Html();
|
||||||
module.exports[diffName] = diffObject;
|
module.exports.Diff2Html = diffObject;
|
||||||
// Expose diff2html in the browser
|
|
||||||
global[diffName] = diffObject;
|
|
||||||
|
|
||||||
})(this);
|
// Expose diff2html in the browser
|
||||||
|
global.Diff2Html = diffObject;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
||||||
|
|
||||||
|
|
@ -168,7 +168,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var utils = __webpack_require__(2).Utils;
|
var utils = __webpack_require__(2).Utils;
|
||||||
|
|
||||||
|
|
@ -194,6 +194,7 @@
|
||||||
var newLine = null;
|
var newLine = null;
|
||||||
|
|
||||||
var saveBlock = function() {
|
var saveBlock = function() {
|
||||||
|
|
||||||
/* Add previous block(if exists) before start a new file */
|
/* Add previous block(if exists) before start a new file */
|
||||||
if (currentBlock) {
|
if (currentBlock) {
|
||||||
currentFile.blocks.push(currentBlock);
|
currentFile.blocks.push(currentBlock);
|
||||||
|
|
@ -202,6 +203,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var saveFile = function() {
|
var saveFile = function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add previous file(if exists) before start a new one
|
* Add previous file(if exists) before start a new one
|
||||||
* if it has name (to avoid binary files errors)
|
* if it has name (to avoid binary files errors)
|
||||||
|
|
@ -379,14 +381,14 @@
|
||||||
var nameSplit = filename.split('.');
|
var nameSplit = filename.split('.');
|
||||||
if (nameSplit.length > 1) {
|
if (nameSplit.length > 1) {
|
||||||
return nameSplit[nameSplit.length - 1];
|
return nameSplit[nameSplit.length - 1];
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
module.exports['DiffParser'] = new DiffParser();
|
module.exports.DiffParser = new DiffParser();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -400,7 +402,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
function Utils() {
|
function Utils() {
|
||||||
}
|
}
|
||||||
|
|
@ -414,7 +416,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.getRandomId = function(prefix) {
|
Utils.prototype.getRandomId = function(prefix) {
|
||||||
return prefix + "-" + Math.random().toString(36).slice(-3);
|
return prefix + '-' + Math.random().toString(36).slice(-3);
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.startsWith = function(str, start) {
|
Utils.prototype.startsWith = function(str, start) {
|
||||||
|
|
@ -436,9 +438,9 @@
|
||||||
return value ? value : '';
|
return value ? value : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports['Utils'] = new Utils();
|
module.exports.Utils = new Utils();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -452,7 +454,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var printerUtils = __webpack_require__(4).PrinterUtils;
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
||||||
var utils = __webpack_require__(2).Utils;
|
var utils = __webpack_require__(2).Utils;
|
||||||
|
|
@ -461,8 +463,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
FileListPrinter.prototype.generateFileList = function(diffFiles) {
|
FileListPrinter.prototype.generateFileList = function(diffFiles) {
|
||||||
var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page
|
var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page
|
||||||
var showId = utils.getRandomId("d2h-show");
|
var showId = utils.getRandomId('d2h-show');
|
||||||
return '<div class="d2h-file-list-wrapper">\n' +
|
return '<div class="d2h-file-list-wrapper">\n' +
|
||||||
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')  </div>\n' +
|
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')  </div>\n' +
|
||||||
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
|
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
|
||||||
|
|
@ -480,14 +482,14 @@
|
||||||
' <span>-' + file.deletedLines + '</span>\n' +
|
' <span>-' + file.deletedLines + '</span>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '"> ' + printerUtils.getDiffName(file) + '</a></td>\n' +
|
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '"> ' + printerUtils.getDiffName(file) + '</a></td>\n' +
|
||||||
' </tr>\n'
|
' </tr>\n';
|
||||||
}).join('\n') +
|
}).join('\n') +
|
||||||
'</table></div>\n';
|
'</table></div>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports['FileListPrinter'] = new FileListPrinter();
|
module.exports.FileListPrinter = new FileListPrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -501,7 +503,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var jsDiff = __webpack_require__(5);
|
var jsDiff = __webpack_require__(5);
|
||||||
var utils = __webpack_require__(2).Utils;
|
var utils = __webpack_require__(2).Utils;
|
||||||
|
|
@ -512,38 +514,40 @@
|
||||||
|
|
||||||
PrinterUtils.prototype.getHtmlId = function(file) {
|
PrinterUtils.prototype.getHtmlId = function(file) {
|
||||||
var hashCode = function(text) {
|
var hashCode = function(text) {
|
||||||
var hash = 0, i, chr, len;
|
var i, chr, len;
|
||||||
if (text.length == 0) return hash;
|
var hash = 0;
|
||||||
|
|
||||||
|
if (text.length === 0) return hash;
|
||||||
|
|
||||||
for (i = 0, len = text.length; i < len; i++) {
|
for (i = 0, len = text.length; i < len; i++) {
|
||||||
chr = text.charCodeAt(i);
|
chr = text.charCodeAt(i);
|
||||||
hash = ((hash << 5) - hash) + chr;
|
hash = ((hash << 5) - hash) + chr;
|
||||||
hash |= 0; // Convert to 32bit integer
|
hash |= 0; // Convert to 32bit integer
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
return "d2h-" + hashCode(this.getDiffName(file)).toString().slice(-6);
|
return 'd2h-' + hashCode(this.getDiffName(file)).toString().slice(-6);
|
||||||
};
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.getDiffName = function(file) {
|
PrinterUtils.prototype.getDiffName = function(file) {
|
||||||
var oldFilename = file.oldName;
|
var oldFilename = file.oldName;
|
||||||
var newFilename = file.newName;
|
var newFilename = file.newName;
|
||||||
|
|
||||||
if (oldFilename && newFilename
|
if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) {
|
||||||
&& oldFilename !== newFilename
|
|
||||||
&& !isDeletedName(newFilename)) {
|
|
||||||
return oldFilename + ' -> ' + newFilename;
|
return oldFilename + ' -> ' + newFilename;
|
||||||
} else if (newFilename && !isDeletedName(newFilename)) {
|
} else if (newFilename && !isDeletedName(newFilename)) {
|
||||||
return newFilename;
|
return newFilename;
|
||||||
} else if (oldFilename) {
|
} else if (oldFilename) {
|
||||||
return oldFilename;
|
return oldFilename;
|
||||||
} else {
|
|
||||||
return 'Unknown filename';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'Unknown filename';
|
||||||
};
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
|
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
|
||||||
var lineStart1, lineStart2;
|
var linePrefix1, linePrefix2, unprefixedLine1, unprefixedLine2;
|
||||||
|
|
||||||
var prefixSize = 1;
|
var prefixSize = 1;
|
||||||
|
|
||||||
|
|
@ -551,17 +555,16 @@
|
||||||
prefixSize = 2;
|
prefixSize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
lineStart1 = diffLine1.substr(0, prefixSize);
|
linePrefix1 = diffLine1.substr(0, prefixSize);
|
||||||
lineStart2 = diffLine2.substr(0, prefixSize);
|
linePrefix2 = diffLine2.substr(0, prefixSize);
|
||||||
|
unprefixedLine1 = diffLine1.substr(prefixSize);
|
||||||
diffLine1 = diffLine1.substr(prefixSize);
|
unprefixedLine2 = diffLine2.substr(prefixSize);
|
||||||
diffLine2 = diffLine2.substr(prefixSize);
|
|
||||||
|
|
||||||
var diff;
|
var diff;
|
||||||
if (config.charByChar) {
|
if (config.charByChar) {
|
||||||
diff = jsDiff.diffChars(diffLine1, diffLine2);
|
diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
|
||||||
} else {
|
} else {
|
||||||
diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2);
|
diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
|
||||||
}
|
}
|
||||||
|
|
||||||
var highlightedLine = '';
|
var highlightedLine = '';
|
||||||
|
|
@ -569,25 +572,30 @@
|
||||||
var changedWords = [];
|
var changedWords = [];
|
||||||
if (!config.charByChar && config.matching === 'words') {
|
if (!config.charByChar && config.matching === 'words') {
|
||||||
var treshold = 0.25;
|
var treshold = 0.25;
|
||||||
if (typeof(config.matchWordsThreshold) !== "undefined") {
|
|
||||||
|
if (typeof(config.matchWordsThreshold) !== 'undefined') {
|
||||||
treshold = config.matchWordsThreshold;
|
treshold = config.matchWordsThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
var matcher = Rematch.rematch(function(a, b) {
|
var matcher = Rematch.rematch(function(a, b) {
|
||||||
var amod = a.value,
|
var amod = a.value;
|
||||||
bmod = b.value,
|
var bmod = b.value;
|
||||||
result = Rematch.distance(amod, bmod);
|
|
||||||
return result;
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
var removed = diff.filter(function isRemoved(element) {
|
var removed = diff.filter(function isRemoved(element) {
|
||||||
return element.removed;
|
return element.removed;
|
||||||
});
|
});
|
||||||
|
|
||||||
var added = diff.filter(function isAdded(element) {
|
var added = diff.filter(function isAdded(element) {
|
||||||
return element.added;
|
return element.added;
|
||||||
});
|
});
|
||||||
|
|
||||||
var chunks = matcher(added, removed);
|
var chunks = matcher(added, removed);
|
||||||
chunks = chunks.forEach(function(chunk){
|
chunks.forEach(function(chunk) {
|
||||||
if (chunk[0].length === 1 && chunk[1].length === 1) {
|
if (chunk[0].length === 1 && chunk[1].length === 1) {
|
||||||
var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value)
|
var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value);
|
||||||
if (dist < treshold) {
|
if (dist < treshold) {
|
||||||
changedWords.push(chunk[0][0]);
|
changedWords.push(chunk[0][0]);
|
||||||
changedWords.push(chunk[1][0]);
|
changedWords.push(chunk[1][0]);
|
||||||
|
|
@ -595,6 +603,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
diff.forEach(function(part) {
|
diff.forEach(function(part) {
|
||||||
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
|
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
|
||||||
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
|
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
|
||||||
|
|
@ -609,11 +618,11 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
first: {
|
first: {
|
||||||
prefix: lineStart1,
|
prefix: linePrefix1,
|
||||||
line: removeIns(highlightedLine)
|
line: removeIns(highlightedLine)
|
||||||
},
|
},
|
||||||
second: {
|
second: {
|
||||||
prefix: lineStart2,
|
prefix: linePrefix2,
|
||||||
line: removeDel(highlightedLine)
|
line: removeDel(highlightedLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -631,9 +640,9 @@
|
||||||
return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
|
return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports['PrinterUtils'] = new PrinterUtils();
|
module.exports.PrinterUtils = new PrinterUtils();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -1892,7 +1901,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var Rematch = {};
|
var Rematch = {};
|
||||||
Rematch.arrayToString = function arrayToString(a) {
|
Rematch.arrayToString = function arrayToString(a) {
|
||||||
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
|
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
|
||||||
|
|
@ -1900,7 +1910,7 @@
|
||||||
} else {
|
} else {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011 Andrei Mackenzie
|
Copyright (c) 2011 Andrei Mackenzie
|
||||||
|
|
@ -1938,26 +1948,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return matrix[b.length][a.length];
|
return matrix[b.length][a.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
Rematch.levenshtein = levenshtein;
|
Rematch.levenshtein = levenshtein;
|
||||||
|
|
||||||
Rematch.distance = function distance(x, y) {
|
Rematch.distance = function distance(x, y) {
|
||||||
x = x.trim();
|
x = x.trim();
|
||||||
y = y.trim();
|
y = y.trim();
|
||||||
var lev = levenshtein(x,y),
|
var lev = levenshtein(x, y);
|
||||||
score = lev / (x.length + y.length);
|
var score = lev / (x.length + y.length);
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
};
|
||||||
|
|
||||||
Rematch.rematch = function rematch(distanceFunction) {
|
Rematch.rematch = function rematch(distanceFunction) {
|
||||||
|
|
||||||
function findBestMatch(a, b, cache) {
|
function findBestMatch(a, b, cache) {
|
||||||
var cachecount = 0;
|
var cachecount = 0;
|
||||||
|
|
||||||
for (var key in cache) {
|
for (var key in cache) {
|
||||||
cachecount++;
|
cachecount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bestMatchDist = Infinity;
|
var bestMatchDist = Infinity;
|
||||||
var bestMatch;
|
var bestMatch;
|
||||||
for (var i = 0; i < a.length; ++i) {
|
for (var i = 0; i < a.length; ++i) {
|
||||||
|
|
@ -1976,21 +1989,25 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
}
|
}
|
||||||
function group(a, b, level, cache) {
|
|
||||||
|
|
||||||
|
function group(a, b, level, cache) {
|
||||||
if (typeof(cache) === "undefined") {
|
if (typeof(cache) === "undefined") {
|
||||||
cache = {};
|
cache = {};
|
||||||
}
|
}
|
||||||
var minLength = Math.min(a.length, b.length);
|
|
||||||
var bm = findBestMatch(a, b, cache);
|
var bm = findBestMatch(a, b, cache);
|
||||||
|
|
||||||
if (!level) {
|
if (!level) {
|
||||||
level = 0;
|
level = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bm || (a.length + b.length < 3)) {
|
if (!bm || (a.length + b.length < 3)) {
|
||||||
return [[a, b]];
|
return [[a, b]];
|
||||||
}
|
}
|
||||||
|
|
||||||
var a1 = a.slice(0, bm.indexA),
|
var a1 = a.slice(0, bm.indexA),
|
||||||
b1 = b.slice(0, bm.indexB),
|
b1 = b.slice(0, bm.indexB),
|
||||||
aMatch = [a[bm.indexA]],
|
aMatch = [a[bm.indexA]],
|
||||||
|
|
@ -2004,20 +2021,24 @@
|
||||||
var groupMatch = group(aMatch, bMatch, level + 1, cache);
|
var groupMatch = group(aMatch, bMatch, level + 1, cache);
|
||||||
var group2 = group(a2, b2, level + 1, cache);
|
var group2 = group(a2, b2, level + 1, cache);
|
||||||
var result = groupMatch;
|
var result = groupMatch;
|
||||||
|
|
||||||
if (bm.indexA > 0 || bm.indexB > 0) {
|
if (bm.indexA > 0 || bm.indexB > 0) {
|
||||||
result = group1.concat(result);
|
result = group1.concat(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.length > tailA || b.length > tailB) {
|
if (a.length > tailA || b.length > tailB) {
|
||||||
result = result.concat(group2);
|
result = result.concat(group2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports['Rematch'] = Rematch;
|
module.exports.Rematch = Rematch;
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -2031,21 +2052,24 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var lineByLinePrinter = __webpack_require__(22).LineByLinePrinter;
|
var LineByLinePrinter = __webpack_require__(22).LineByLinePrinter;
|
||||||
var sideBySidePrinter = __webpack_require__(23).SideBySidePrinter;
|
var sideBySidePrinter = __webpack_require__(23).SideBySidePrinter;
|
||||||
|
|
||||||
function HtmlPrinter() {
|
function HtmlPrinter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateLineByLineJsonHtml = lineByLinePrinter.generateLineByLineJsonHtml;
|
HtmlPrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
||||||
|
var lineByLinePrinter = new LineByLinePrinter(config);
|
||||||
|
return lineByLinePrinter.generateLineByLineJsonHtml(diffFiles);
|
||||||
|
};
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
||||||
|
|
||||||
module.exports['HtmlPrinter'] = new HtmlPrinter();
|
module.exports.HtmlPrinter = new HtmlPrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -2059,25 +2083,27 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = __webpack_require__(1).DiffParser;
|
var diffParser = __webpack_require__(1).DiffParser;
|
||||||
var printerUtils = __webpack_require__(4).PrinterUtils;
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
||||||
var utils = __webpack_require__(2).Utils;
|
var utils = __webpack_require__(2).Utils;
|
||||||
var Rematch = __webpack_require__(20).Rematch;
|
var Rematch = __webpack_require__(20).Rematch;
|
||||||
|
|
||||||
function LineByLinePrinter() {
|
function LineByLinePrinter(config) {
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
|
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
|
||||||
|
var that = this;
|
||||||
return '<div class="d2h-wrapper">\n' +
|
return '<div class="d2h-wrapper">\n' +
|
||||||
diffFiles.map(function(file) {
|
diffFiles.map(function(file) {
|
||||||
|
|
||||||
var diffs;
|
var diffs;
|
||||||
if (file.blocks.length) {
|
if (file.blocks.length) {
|
||||||
diffs = generateFileHtml(file, config);
|
diffs = that._generateFileHtml(file);
|
||||||
} else {
|
} else {
|
||||||
diffs = generateEmptyDiff();
|
diffs = that._generateEmptyDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
|
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
|
||||||
|
|
@ -2107,12 +2133,14 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var matcher = Rematch.rematch(function(a, b) {
|
var matcher = Rematch.rematch(function(a, b) {
|
||||||
var amod = a.content.substr(1),
|
var amod = a.content.substr(1);
|
||||||
bmod = b.content.substr(1);
|
var bmod = b.content.substr(1);
|
||||||
|
|
||||||
return Rematch.distance(amod, bmod);
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
function generateFileHtml(file, config) {
|
LineByLinePrinter.prototype._generateFileHtml = function(file) {
|
||||||
|
var that = this;
|
||||||
return file.blocks.map(function(block) {
|
return file.blocks.map(function(block) {
|
||||||
|
|
||||||
var lines = '<tr>\n' +
|
var lines = '<tr>\n' +
|
||||||
|
|
@ -2124,11 +2152,14 @@
|
||||||
|
|
||||||
var oldLines = [];
|
var oldLines = [];
|
||||||
var newLines = [];
|
var newLines = [];
|
||||||
|
|
||||||
function processChangeBlock() {
|
function processChangeBlock() {
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = config.matching === "lines" || config.matching === "words";
|
|
||||||
|
var doMatching = that.config.matching === 'lines' || that.config.matching === 'words';
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
||||||
|
|
@ -2138,36 +2169,36 @@
|
||||||
insertType = diffParser.LINE_TYPE.INSERTS;
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
||||||
deleteType = diffParser.LINE_TYPE.DELETES;
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.forEach(function(match) {
|
matches.forEach(function(match) {
|
||||||
var oldLines = match[0];
|
oldLines = match[0];
|
||||||
var newLines = match[1];
|
newLines = match[1];
|
||||||
|
|
||||||
var processedOldLines = [];
|
var processedOldLines = [];
|
||||||
var processedNewLines = [];
|
var processedNewLines = [];
|
||||||
var j = 0;
|
|
||||||
var oldLine, newLine,
|
var common = Math.min(oldLines.length, newLines.length);
|
||||||
common = Math.min(oldLines.length, newLines.length),
|
|
||||||
max = Math.max(oldLines.length, newLines.length);
|
var oldLine, newLine;
|
||||||
for (j = 0; j < common; j++) {
|
for (var j = 0; j < common; j++) {
|
||||||
oldLine = oldLines[j];
|
oldLine = oldLines[j];
|
||||||
newLine = newLines[j];
|
newLine = newLines[j];
|
||||||
|
|
||||||
config.isCombined = file.isCombined;
|
that.config.isCombined = file.isCombined;
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
processedOldLines +=
|
processedOldLines +=
|
||||||
generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
that._generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
processedNewLines +=
|
processedNewLines +=
|
||||||
generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
that._generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines += processedOldLines + processedNewLines;
|
lines += processedOldLines + processedNewLines;
|
||||||
lines += processLines(oldLines.slice(common), newLines.slice(common));
|
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
|
||||||
|
|
||||||
processedOldLines = [];
|
|
||||||
processedNewLines = [];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
newLines = [];
|
newLines = [];
|
||||||
}
|
}
|
||||||
|
|
@ -2180,16 +2211,17 @@
|
||||||
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
if (line.type == diffParser.LINE_TYPE.CONTEXT) {
|
|
||||||
lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
} else if (line.type == diffParser.LINE_TYPE.DELETES) {
|
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
newLines.push(line);
|
newLines.push(line);
|
||||||
} else {
|
} else {
|
||||||
console.error('unknown state in html line-by-line generator');
|
console.error('Unknown state in html line-by-line generator');
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2198,27 +2230,27 @@
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
}
|
};
|
||||||
|
|
||||||
function processLines(oldLines, newLines) {
|
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
|
||||||
var lines = '';
|
var lines = '';
|
||||||
|
|
||||||
for (j = 0; j < oldLines.length; j++) {
|
for (var i = 0; i < oldLines.length; i++) {
|
||||||
var oldLine = oldLines[j];
|
var oldLine = oldLines[i];
|
||||||
var oldEscapedLine = utils.escape(oldLine.content);
|
var oldEscapedLine = utils.escape(oldLine.content);
|
||||||
lines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
lines += this._generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < newLines.length; j++) {
|
for (var j = 0; j < newLines.length; j++) {
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[j];
|
||||||
var newEscapedLine = utils.escape(newLine.content);
|
var newEscapedLine = utils.escape(newLine.content);
|
||||||
lines += generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
lines += this._generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
};
|
||||||
|
|
||||||
function generateLineHtml(type, oldNumber, newNumber, content, prefix) {
|
LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
||||||
var htmlPrefix = '';
|
var htmlPrefix = '';
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
|
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
|
||||||
|
|
@ -2238,9 +2270,9 @@
|
||||||
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
|
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>\n';
|
'</tr>\n';
|
||||||
}
|
};
|
||||||
|
|
||||||
function generateEmptyDiff() {
|
LineByLinePrinter.prototype._generateEmptyDiff = function() {
|
||||||
return '<tr>\n' +
|
return '<tr>\n' +
|
||||||
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
|
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
|
||||||
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' +
|
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' +
|
||||||
|
|
@ -2248,11 +2280,11 @@
|
||||||
' </div>' +
|
' </div>' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>\n';
|
'</tr>\n';
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports['LineByLinePrinter'] = new LineByLinePrinter();
|
module.exports.LineByLinePrinter = LineByLinePrinter;
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ },
|
/***/ },
|
||||||
|
|
@ -2266,7 +2298,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = __webpack_require__(1).DiffParser;
|
var diffParser = __webpack_require__(1).DiffParser;
|
||||||
var printerUtils = __webpack_require__(4).PrinterUtils;
|
var printerUtils = __webpack_require__(4).PrinterUtils;
|
||||||
|
|
@ -2355,11 +2387,13 @@
|
||||||
|
|
||||||
var oldLines = [];
|
var oldLines = [];
|
||||||
var newLines = [];
|
var newLines = [];
|
||||||
|
|
||||||
function processChangeBlock() {
|
function processChangeBlock() {
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = config.matching === "lines" || config.matching === "words";
|
var doMatching = config.matching === 'lines' || config.matching === 'words';
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
||||||
|
|
@ -2369,17 +2403,17 @@
|
||||||
insertType = diffParser.LINE_TYPE.INSERTS;
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
||||||
deleteType = diffParser.LINE_TYPE.DELETES;
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.forEach(function(match) {
|
matches.forEach(function(match) {
|
||||||
var oldLines = match[0];
|
oldLines = match[0];
|
||||||
var newLines = match[1];
|
newLines = match[1];
|
||||||
var tmpHtml;
|
|
||||||
var j = 0;
|
var common = Math.min(oldLines.length, newLines.length);
|
||||||
var oldLine, newLine,
|
var max = Math.max(oldLines.length, newLines.length);
|
||||||
common = Math.min(oldLines.length, newLines.length),
|
|
||||||
max = Math.max(oldLines.length, newLines.length);
|
for (var j = 0; j < common; j++) {
|
||||||
for (j = 0; j < common; j++) {
|
var oldLine = oldLines[j];
|
||||||
oldLine = oldLines[j];
|
var newLine = newLines[j];
|
||||||
newLine = newLines[j];
|
|
||||||
|
|
||||||
config.isCombined = file.isCombined;
|
config.isCombined = file.isCombined;
|
||||||
|
|
||||||
|
|
@ -2392,17 +2426,21 @@
|
||||||
generateSingleLineHtml(insertType, newLine.newNumber,
|
generateSingleLineHtml(insertType, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max > common) {
|
if (max > common) {
|
||||||
var oldSlice = oldLines.slice(common),
|
var oldSlice = oldLines.slice(common);
|
||||||
newSlice = newLines.slice(common);
|
var newSlice = newLines.slice(common);
|
||||||
tmpHtml = processLines(oldLines.slice(common), newLines.slice(common));
|
|
||||||
|
var tmpHtml = processLines(oldSlice, newSlice);
|
||||||
fileHtml.left += tmpHtml.left;
|
fileHtml.left += tmpHtml.left;
|
||||||
fileHtml.right += tmpHtml.right;
|
fileHtml.right += tmpHtml.right;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
newLines = [];
|
newLines = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < block.lines.length; i++) {
|
for (var i = 0; i < block.lines.length; i++) {
|
||||||
var line = block.lines[i];
|
var line = block.lines[i];
|
||||||
var prefix = line[0];
|
var prefix = line[0];
|
||||||
|
|
@ -2412,15 +2450,16 @@
|
||||||
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
if (line.type == diffParser.LINE_TYPE.CONTEXT) {
|
|
||||||
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
||||||
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
newLines.push(line);
|
newLines.push(line);
|
||||||
} else {
|
} else {
|
||||||
console.error('unknown state in html side-by-side generator');
|
console.error('unknown state in html side-by-side generator');
|
||||||
|
|
@ -2440,21 +2479,24 @@
|
||||||
fileHtml.right = '';
|
fileHtml.right = '';
|
||||||
|
|
||||||
var maxLinesNumber = Math.max(oldLines.length, newLines.length);
|
var maxLinesNumber = Math.max(oldLines.length, newLines.length);
|
||||||
for (j = 0; j < maxLinesNumber; j++) {
|
for (var i = 0; i < maxLinesNumber; i++) {
|
||||||
var oldLine = oldLines[j];
|
var oldLine = oldLines[i];
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[i];
|
||||||
var oldContent;
|
var oldContent;
|
||||||
var newContent;
|
var newContent;
|
||||||
var oldPrefix;
|
var oldPrefix;
|
||||||
var newPrefix;
|
var newPrefix;
|
||||||
|
|
||||||
if (oldLine) {
|
if (oldLine) {
|
||||||
oldContent = utils.escape(oldLine.content.substr(1));
|
oldContent = utils.escape(oldLine.content.substr(1));
|
||||||
oldPrefix = oldLine.content[0];
|
oldPrefix = oldLine.content[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newLine) {
|
if (newLine) {
|
||||||
newContent = utils.escape(newLine.content.substr(1));
|
newContent = utils.escape(newLine.content.substr(1));
|
||||||
newPrefix = newLine.content[0];
|
newPrefix = newLine.content[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldLine && newLine) {
|
if (oldLine && newLine) {
|
||||||
fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
|
|
@ -2506,9 +2548,9 @@
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports['SideBySidePrinter'] = new SideBySidePrinter();
|
module.exports.SideBySidePrinter = new SideBySidePrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
||||||
|
|
||||||
/***/ }
|
/***/ }
|
||||||
|
|
|
||||||
4
dist/diff2html.min.js
vendored
4
dist/diff2html.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var utils = require('./utils.js').Utils;
|
var utils = require('./utils.js').Utils;
|
||||||
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
var newLine = null;
|
var newLine = null;
|
||||||
|
|
||||||
var saveBlock = function() {
|
var saveBlock = function() {
|
||||||
|
|
||||||
/* Add previous block(if exists) before start a new file */
|
/* Add previous block(if exists) before start a new file */
|
||||||
if (currentBlock) {
|
if (currentBlock) {
|
||||||
currentFile.blocks.push(currentBlock);
|
currentFile.blocks.push(currentBlock);
|
||||||
|
|
@ -39,6 +40,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var saveFile = function() {
|
var saveFile = function() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add previous file(if exists) before start a new one
|
* Add previous file(if exists) before start a new one
|
||||||
* if it has name (to avoid binary files errors)
|
* if it has name (to avoid binary files errors)
|
||||||
|
|
@ -216,11 +218,11 @@
|
||||||
var nameSplit = filename.split('.');
|
var nameSplit = filename.split('.');
|
||||||
if (nameSplit.length > 1) {
|
if (nameSplit.length > 1) {
|
||||||
return nameSplit[nameSplit.length - 1];
|
return nameSplit[nameSplit.length - 1];
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
module.exports['DiffParser'] = new DiffParser();
|
module.exports.DiffParser = new DiffParser();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = require('./diff-parser.js').DiffParser;
|
var diffParser = require('./diff-parser.js').DiffParser;
|
||||||
var fileLister = require('./file-list-printer.js').FileListPrinter;
|
var fileLister = require('./file-list-printer.js').FileListPrinter;
|
||||||
|
|
@ -17,9 +17,9 @@
|
||||||
/*
|
/*
|
||||||
* Line diff type configuration
|
* Line diff type configuration
|
||||||
var config = {
|
var config = {
|
||||||
"wordByWord": true, // (default)
|
'wordByWord': true, // (default)
|
||||||
// OR
|
// OR
|
||||||
"charByChar": true
|
'charByChar': true
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -41,19 +41,19 @@
|
||||||
diffJson = diffParser.generateDiffJson(diffInput);
|
diffJson = diffParser.generateDiffJson(diffInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
var fileList = "";
|
var fileList = '';
|
||||||
if (configOrEmpty.showFiles === true) {
|
if (configOrEmpty.showFiles === true) {
|
||||||
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
|
fileList = fileLister.generateFileList(diffJson, configOrEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
var diffOutput = "";
|
var diffOutput = '';
|
||||||
if (configOrEmpty.outputFormat === 'side-by-side') {
|
if (configOrEmpty.outputFormat === 'side-by-side') {
|
||||||
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
||||||
} else {
|
} else {
|
||||||
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileList + diffOutput
|
return fileList + diffOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,9 +66,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'diff';
|
configOrEmpty.inputFormat = 'diff';
|
||||||
configOrEmpty['outputFormat'] = 'line-by-line';
|
configOrEmpty.outputFormat = 'line-by-line';
|
||||||
return this.getPrettyHtml(diffInput, configOrEmpty)
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -76,9 +76,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'json';
|
configOrEmpty.inputFormat = 'json';
|
||||||
configOrEmpty['outputFormat'] = 'line-by-line';
|
configOrEmpty.outputFormat = 'line-by-line';
|
||||||
return this.getPrettyHtml(diffJson, configOrEmpty)
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -86,9 +86,9 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'diff';
|
configOrEmpty.inputFormat = 'diff';
|
||||||
configOrEmpty['outputFormat'] = 'side-by-side';
|
configOrEmpty.outputFormat = 'side-by-side';
|
||||||
return this.getPrettyHtml(diffInput, configOrEmpty)
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -96,15 +96,15 @@
|
||||||
*/
|
*/
|
||||||
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
||||||
var configOrEmpty = config || {};
|
var configOrEmpty = config || {};
|
||||||
configOrEmpty['inputFormat'] = 'json';
|
configOrEmpty.inputFormat = 'json';
|
||||||
configOrEmpty['outputFormat'] = 'side-by-side';
|
configOrEmpty.outputFormat = 'side-by-side';
|
||||||
return this.getPrettyHtml(diffJson, configOrEmpty)
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
||||||
};
|
};
|
||||||
|
|
||||||
var diffName = 'Diff2Html';
|
|
||||||
var diffObject = new Diff2Html();
|
var diffObject = new Diff2Html();
|
||||||
module.exports[diffName] = diffObject;
|
module.exports.Diff2Html = diffObject;
|
||||||
// Expose diff2html in the browser
|
|
||||||
global[diffName] = diffObject;
|
|
||||||
|
|
||||||
})(this);
|
// Expose diff2html in the browser
|
||||||
|
global.Diff2Html = diffObject;
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
||||||
var utils = require('./utils.js').Utils;
|
var utils = require('./utils.js').Utils;
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
FileListPrinter.prototype.generateFileList = function(diffFiles) {
|
FileListPrinter.prototype.generateFileList = function(diffFiles) {
|
||||||
var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page
|
var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page
|
||||||
var showId = utils.getRandomId("d2h-show");
|
var showId = utils.getRandomId('d2h-show');
|
||||||
return '<div class="d2h-file-list-wrapper">\n' +
|
return '<div class="d2h-file-list-wrapper">\n' +
|
||||||
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')  </div>\n' +
|
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')  </div>\n' +
|
||||||
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
|
' <a id="' + hideId + '" class="d2h-hide" href="#' + hideId + '">+</a>\n' +
|
||||||
|
|
@ -33,11 +33,11 @@
|
||||||
' <span>-' + file.deletedLines + '</span>\n' +
|
' <span>-' + file.deletedLines + '</span>\n' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '"> ' + printerUtils.getDiffName(file) + '</a></td>\n' +
|
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '"> ' + printerUtils.getDiffName(file) + '</a></td>\n' +
|
||||||
' </tr>\n'
|
' </tr>\n';
|
||||||
}).join('\n') +
|
}).join('\n') +
|
||||||
'</table></div>\n';
|
'</table></div>\n';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports['FileListPrinter'] = new FileListPrinter();
|
module.exports.FileListPrinter = new FileListPrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
|
var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
|
||||||
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
|
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
|
||||||
|
|
@ -20,6 +20,6 @@
|
||||||
|
|
||||||
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml;
|
||||||
|
|
||||||
module.exports['HtmlPrinter'] = new HtmlPrinter();
|
module.exports.HtmlPrinter = new HtmlPrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = require('./diff-parser.js').DiffParser;
|
var diffParser = require('./diff-parser.js').DiffParser;
|
||||||
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
||||||
|
|
@ -23,9 +23,9 @@
|
||||||
|
|
||||||
var diffs;
|
var diffs;
|
||||||
if (file.blocks.length) {
|
if (file.blocks.length) {
|
||||||
diffs = that.generateFileHtml(file);
|
diffs = that._generateFileHtml(file);
|
||||||
} else {
|
} else {
|
||||||
diffs = that.generateEmptyDiff();
|
diffs = that._generateEmptyDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
|
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
|
||||||
|
|
@ -55,12 +55,13 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var matcher = Rematch.rematch(function(a, b) {
|
var matcher = Rematch.rematch(function(a, b) {
|
||||||
var amod = a.content.substr(1),
|
var amod = a.content.substr(1);
|
||||||
bmod = b.content.substr(1);
|
var bmod = b.content.substr(1);
|
||||||
|
|
||||||
return Rematch.distance(amod, bmod);
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateFileHtml = function(file) {
|
LineByLinePrinter.prototype._generateFileHtml = function(file) {
|
||||||
var that = this;
|
var that = this;
|
||||||
return file.blocks.map(function(block) {
|
return file.blocks.map(function(block) {
|
||||||
|
|
||||||
|
|
@ -73,11 +74,14 @@
|
||||||
|
|
||||||
var oldLines = [];
|
var oldLines = [];
|
||||||
var newLines = [];
|
var newLines = [];
|
||||||
|
|
||||||
function processChangeBlock() {
|
function processChangeBlock() {
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = that.config.matching === "lines" || that.config.matching === "words";
|
|
||||||
|
var doMatching = that.config.matching === 'lines' || that.config.matching === 'words';
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
||||||
|
|
@ -87,16 +91,18 @@
|
||||||
insertType = diffParser.LINE_TYPE.INSERTS;
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
||||||
deleteType = diffParser.LINE_TYPE.DELETES;
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.forEach(function(match) {
|
matches.forEach(function(match) {
|
||||||
var oldLines = match[0];
|
oldLines = match[0];
|
||||||
var newLines = match[1];
|
newLines = match[1];
|
||||||
|
|
||||||
var processedOldLines = [];
|
var processedOldLines = [];
|
||||||
var processedNewLines = [];
|
var processedNewLines = [];
|
||||||
var j = 0;
|
|
||||||
var oldLine, newLine,
|
var common = Math.min(oldLines.length, newLines.length);
|
||||||
common = Math.min(oldLines.length, newLines.length),
|
|
||||||
max = Math.max(oldLines.length, newLines.length);
|
var oldLine, newLine;
|
||||||
for (j = 0; j < common; j++) {
|
for (var j = 0; j < common; j++) {
|
||||||
oldLine = oldLines[j];
|
oldLine = oldLines[j];
|
||||||
newLine = newLines[j];
|
newLine = newLines[j];
|
||||||
|
|
||||||
|
|
@ -104,19 +110,17 @@
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
processedOldLines +=
|
processedOldLines +=
|
||||||
that.generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
that._generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
processedNewLines +=
|
processedNewLines +=
|
||||||
that.generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
that._generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines += processedOldLines + processedNewLines;
|
lines += processedOldLines + processedNewLines;
|
||||||
lines += that.processLines(oldLines.slice(common), newLines.slice(common));
|
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
|
||||||
|
|
||||||
processedOldLines = [];
|
|
||||||
processedNewLines = [];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
newLines = [];
|
newLines = [];
|
||||||
}
|
}
|
||||||
|
|
@ -129,16 +133,17 @@
|
||||||
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
if (line.type == diffParser.LINE_TYPE.CONTEXT) {
|
|
||||||
lines += that.generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
lines += that.generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
} else if (line.type == diffParser.LINE_TYPE.DELETES) {
|
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
newLines.push(line);
|
newLines.push(line);
|
||||||
} else {
|
} else {
|
||||||
console.error('unknown state in html line-by-line generator');
|
console.error('Unknown state in html line-by-line generator');
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,27 +152,27 @@
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
}
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype.processLines = function(oldLines, newLines) {
|
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
|
||||||
var lines = '';
|
var lines = '';
|
||||||
|
|
||||||
for (j = 0; j < oldLines.length; j++) {
|
for (var i = 0; i < oldLines.length; i++) {
|
||||||
var oldLine = oldLines[j];
|
var oldLine = oldLines[i];
|
||||||
var oldEscapedLine = utils.escape(oldLine.content);
|
var oldEscapedLine = utils.escape(oldLine.content);
|
||||||
lines += this.generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
lines += this._generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < newLines.length; j++) {
|
for (var j = 0; j < newLines.length; j++) {
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[j];
|
||||||
var newEscapedLine = utils.escape(newLine.content);
|
var newEscapedLine = utils.escape(newLine.content);
|
||||||
lines += this.generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
lines += this._generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
||||||
var htmlPrefix = '';
|
var htmlPrefix = '';
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
|
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
|
||||||
|
|
@ -187,9 +192,9 @@
|
||||||
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
|
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>\n';
|
'</tr>\n';
|
||||||
}
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype.generateEmptyDiff = function() {
|
LineByLinePrinter.prototype._generateEmptyDiff = function() {
|
||||||
return '<tr>\n' +
|
return '<tr>\n' +
|
||||||
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
|
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
|
||||||
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' +
|
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' +
|
||||||
|
|
@ -197,8 +202,8 @@
|
||||||
' </div>' +
|
' </div>' +
|
||||||
' </td>\n' +
|
' </td>\n' +
|
||||||
'</tr>\n';
|
'</tr>\n';
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports['LineByLinePrinter'] = LineByLinePrinter;
|
module.exports.LineByLinePrinter = LineByLinePrinter;
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var jsDiff = require('diff');
|
var jsDiff = require('diff');
|
||||||
var utils = require('./utils.js').Utils;
|
var utils = require('./utils.js').Utils;
|
||||||
|
|
@ -16,38 +16,40 @@
|
||||||
|
|
||||||
PrinterUtils.prototype.getHtmlId = function(file) {
|
PrinterUtils.prototype.getHtmlId = function(file) {
|
||||||
var hashCode = function(text) {
|
var hashCode = function(text) {
|
||||||
var hash = 0, i, chr, len;
|
var i, chr, len;
|
||||||
if (text.length == 0) return hash;
|
var hash = 0;
|
||||||
|
|
||||||
|
if (text.length === 0) return hash;
|
||||||
|
|
||||||
for (i = 0, len = text.length; i < len; i++) {
|
for (i = 0, len = text.length; i < len; i++) {
|
||||||
chr = text.charCodeAt(i);
|
chr = text.charCodeAt(i);
|
||||||
hash = ((hash << 5) - hash) + chr;
|
hash = ((hash << 5) - hash) + chr;
|
||||||
hash |= 0; // Convert to 32bit integer
|
hash |= 0; // Convert to 32bit integer
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
return "d2h-" + hashCode(this.getDiffName(file)).toString().slice(-6);
|
return 'd2h-' + hashCode(this.getDiffName(file)).toString().slice(-6);
|
||||||
};
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.getDiffName = function(file) {
|
PrinterUtils.prototype.getDiffName = function(file) {
|
||||||
var oldFilename = file.oldName;
|
var oldFilename = file.oldName;
|
||||||
var newFilename = file.newName;
|
var newFilename = file.newName;
|
||||||
|
|
||||||
if (oldFilename && newFilename
|
if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) {
|
||||||
&& oldFilename !== newFilename
|
|
||||||
&& !isDeletedName(newFilename)) {
|
|
||||||
return oldFilename + ' -> ' + newFilename;
|
return oldFilename + ' -> ' + newFilename;
|
||||||
} else if (newFilename && !isDeletedName(newFilename)) {
|
} else if (newFilename && !isDeletedName(newFilename)) {
|
||||||
return newFilename;
|
return newFilename;
|
||||||
} else if (oldFilename) {
|
} else if (oldFilename) {
|
||||||
return oldFilename;
|
return oldFilename;
|
||||||
} else {
|
|
||||||
return 'Unknown filename';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'Unknown filename';
|
||||||
};
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
|
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
|
||||||
var lineStart1, lineStart2;
|
var linePrefix1, linePrefix2, unprefixedLine1, unprefixedLine2;
|
||||||
|
|
||||||
var prefixSize = 1;
|
var prefixSize = 1;
|
||||||
|
|
||||||
|
|
@ -55,17 +57,16 @@
|
||||||
prefixSize = 2;
|
prefixSize = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
lineStart1 = diffLine1.substr(0, prefixSize);
|
linePrefix1 = diffLine1.substr(0, prefixSize);
|
||||||
lineStart2 = diffLine2.substr(0, prefixSize);
|
linePrefix2 = diffLine2.substr(0, prefixSize);
|
||||||
|
unprefixedLine1 = diffLine1.substr(prefixSize);
|
||||||
diffLine1 = diffLine1.substr(prefixSize);
|
unprefixedLine2 = diffLine2.substr(prefixSize);
|
||||||
diffLine2 = diffLine2.substr(prefixSize);
|
|
||||||
|
|
||||||
var diff;
|
var diff;
|
||||||
if (config.charByChar) {
|
if (config.charByChar) {
|
||||||
diff = jsDiff.diffChars(diffLine1, diffLine2);
|
diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2);
|
||||||
} else {
|
} else {
|
||||||
diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2);
|
diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2);
|
||||||
}
|
}
|
||||||
|
|
||||||
var highlightedLine = '';
|
var highlightedLine = '';
|
||||||
|
|
@ -73,25 +74,30 @@
|
||||||
var changedWords = [];
|
var changedWords = [];
|
||||||
if (!config.charByChar && config.matching === 'words') {
|
if (!config.charByChar && config.matching === 'words') {
|
||||||
var treshold = 0.25;
|
var treshold = 0.25;
|
||||||
if (typeof(config.matchWordsThreshold) !== "undefined") {
|
|
||||||
|
if (typeof(config.matchWordsThreshold) !== 'undefined') {
|
||||||
treshold = config.matchWordsThreshold;
|
treshold = config.matchWordsThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
var matcher = Rematch.rematch(function(a, b) {
|
var matcher = Rematch.rematch(function(a, b) {
|
||||||
var amod = a.value,
|
var amod = a.value;
|
||||||
bmod = b.value,
|
var bmod = b.value;
|
||||||
result = Rematch.distance(amod, bmod);
|
|
||||||
return result;
|
return Rematch.distance(amod, bmod);
|
||||||
});
|
});
|
||||||
|
|
||||||
var removed = diff.filter(function isRemoved(element) {
|
var removed = diff.filter(function isRemoved(element) {
|
||||||
return element.removed;
|
return element.removed;
|
||||||
});
|
});
|
||||||
|
|
||||||
var added = diff.filter(function isAdded(element) {
|
var added = diff.filter(function isAdded(element) {
|
||||||
return element.added;
|
return element.added;
|
||||||
});
|
});
|
||||||
|
|
||||||
var chunks = matcher(added, removed);
|
var chunks = matcher(added, removed);
|
||||||
chunks = chunks.forEach(function(chunk){
|
chunks.forEach(function(chunk) {
|
||||||
if (chunk[0].length === 1 && chunk[1].length === 1) {
|
if (chunk[0].length === 1 && chunk[1].length === 1) {
|
||||||
var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value)
|
var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value);
|
||||||
if (dist < treshold) {
|
if (dist < treshold) {
|
||||||
changedWords.push(chunk[0][0]);
|
changedWords.push(chunk[0][0]);
|
||||||
changedWords.push(chunk[1][0]);
|
changedWords.push(chunk[1][0]);
|
||||||
|
|
@ -99,6 +105,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
diff.forEach(function(part) {
|
diff.forEach(function(part) {
|
||||||
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
|
var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : '';
|
||||||
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
|
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
|
||||||
|
|
@ -113,11 +120,11 @@
|
||||||
|
|
||||||
return {
|
return {
|
||||||
first: {
|
first: {
|
||||||
prefix: lineStart1,
|
prefix: linePrefix1,
|
||||||
line: removeIns(highlightedLine)
|
line: removeIns(highlightedLine)
|
||||||
},
|
},
|
||||||
second: {
|
second: {
|
||||||
prefix: lineStart2,
|
prefix: linePrefix2,
|
||||||
line: removeDel(highlightedLine)
|
line: removeDel(highlightedLine)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,6 +142,6 @@
|
||||||
return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
|
return line.replace(/(<del[^>]*>((.|\n)*?)<\/del>)/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports['PrinterUtils'] = new PrinterUtils();
|
module.exports.PrinterUtils = new PrinterUtils();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var Rematch = {};
|
var Rematch = {};
|
||||||
Rematch.arrayToString = function arrayToString(a) {
|
Rematch.arrayToString = function arrayToString(a) {
|
||||||
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
|
if (Object.prototype.toString.apply(a, []) === "[object Array]") {
|
||||||
|
|
@ -14,7 +15,7 @@
|
||||||
} else {
|
} else {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011 Andrei Mackenzie
|
Copyright (c) 2011 Andrei Mackenzie
|
||||||
|
|
@ -52,26 +53,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return matrix[b.length][a.length];
|
return matrix[b.length][a.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
Rematch.levenshtein = levenshtein;
|
Rematch.levenshtein = levenshtein;
|
||||||
|
|
||||||
Rematch.distance = function distance(x, y) {
|
Rematch.distance = function distance(x, y) {
|
||||||
x = x.trim();
|
x = x.trim();
|
||||||
y = y.trim();
|
y = y.trim();
|
||||||
var lev = levenshtein(x,y),
|
var lev = levenshtein(x, y);
|
||||||
score = lev / (x.length + y.length);
|
var score = lev / (x.length + y.length);
|
||||||
|
|
||||||
return score;
|
return score;
|
||||||
}
|
};
|
||||||
|
|
||||||
Rematch.rematch = function rematch(distanceFunction) {
|
Rematch.rematch = function rematch(distanceFunction) {
|
||||||
|
|
||||||
function findBestMatch(a, b, cache) {
|
function findBestMatch(a, b, cache) {
|
||||||
var cachecount = 0;
|
var cachecount = 0;
|
||||||
|
|
||||||
for (var key in cache) {
|
for (var key in cache) {
|
||||||
cachecount++;
|
cachecount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
var bestMatchDist = Infinity;
|
var bestMatchDist = Infinity;
|
||||||
var bestMatch;
|
var bestMatch;
|
||||||
for (var i = 0; i < a.length; ++i) {
|
for (var i = 0; i < a.length; ++i) {
|
||||||
|
|
@ -90,21 +94,25 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
}
|
}
|
||||||
function group(a, b, level, cache) {
|
|
||||||
|
|
||||||
|
function group(a, b, level, cache) {
|
||||||
if (typeof(cache) === "undefined") {
|
if (typeof(cache) === "undefined") {
|
||||||
cache = {};
|
cache = {};
|
||||||
}
|
}
|
||||||
var minLength = Math.min(a.length, b.length);
|
|
||||||
var bm = findBestMatch(a, b, cache);
|
var bm = findBestMatch(a, b, cache);
|
||||||
|
|
||||||
if (!level) {
|
if (!level) {
|
||||||
level = 0;
|
level = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bm || (a.length + b.length < 3)) {
|
if (!bm || (a.length + b.length < 3)) {
|
||||||
return [[a, b]];
|
return [[a, b]];
|
||||||
}
|
}
|
||||||
|
|
||||||
var a1 = a.slice(0, bm.indexA),
|
var a1 = a.slice(0, bm.indexA),
|
||||||
b1 = b.slice(0, bm.indexB),
|
b1 = b.slice(0, bm.indexB),
|
||||||
aMatch = [a[bm.indexA]],
|
aMatch = [a[bm.indexA]],
|
||||||
|
|
@ -118,17 +126,21 @@
|
||||||
var groupMatch = group(aMatch, bMatch, level + 1, cache);
|
var groupMatch = group(aMatch, bMatch, level + 1, cache);
|
||||||
var group2 = group(a2, b2, level + 1, cache);
|
var group2 = group(a2, b2, level + 1, cache);
|
||||||
var result = groupMatch;
|
var result = groupMatch;
|
||||||
|
|
||||||
if (bm.indexA > 0 || bm.indexB > 0) {
|
if (bm.indexA > 0 || bm.indexB > 0) {
|
||||||
result = group1.concat(result);
|
result = group1.concat(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.length > tailA || b.length > tailB) {
|
if (a.length > tailA || b.length > tailB) {
|
||||||
result = result.concat(group2);
|
result = result.concat(group2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports['Rematch'] = Rematch;
|
module.exports.Rematch = Rematch;
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
var diffParser = require('./diff-parser.js').DiffParser;
|
var diffParser = require('./diff-parser.js').DiffParser;
|
||||||
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
var printerUtils = require('./printer-utils.js').PrinterUtils;
|
||||||
|
|
@ -94,11 +94,13 @@
|
||||||
|
|
||||||
var oldLines = [];
|
var oldLines = [];
|
||||||
var newLines = [];
|
var newLines = [];
|
||||||
|
|
||||||
function processChangeBlock() {
|
function processChangeBlock() {
|
||||||
var matches;
|
var matches;
|
||||||
var insertType;
|
var insertType;
|
||||||
var deleteType;
|
var deleteType;
|
||||||
var doMatching = config.matching === "lines" || config.matching === "words";
|
var doMatching = config.matching === 'lines' || config.matching === 'words';
|
||||||
|
|
||||||
if (doMatching) {
|
if (doMatching) {
|
||||||
matches = matcher(oldLines, newLines);
|
matches = matcher(oldLines, newLines);
|
||||||
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
insertType = diffParser.LINE_TYPE.INSERT_CHANGES;
|
||||||
|
|
@ -108,17 +110,17 @@
|
||||||
insertType = diffParser.LINE_TYPE.INSERTS;
|
insertType = diffParser.LINE_TYPE.INSERTS;
|
||||||
deleteType = diffParser.LINE_TYPE.DELETES;
|
deleteType = diffParser.LINE_TYPE.DELETES;
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.forEach(function(match) {
|
matches.forEach(function(match) {
|
||||||
var oldLines = match[0];
|
oldLines = match[0];
|
||||||
var newLines = match[1];
|
newLines = match[1];
|
||||||
var tmpHtml;
|
|
||||||
var j = 0;
|
var common = Math.min(oldLines.length, newLines.length);
|
||||||
var oldLine, newLine,
|
var max = Math.max(oldLines.length, newLines.length);
|
||||||
common = Math.min(oldLines.length, newLines.length),
|
|
||||||
max = Math.max(oldLines.length, newLines.length);
|
for (var j = 0; j < common; j++) {
|
||||||
for (j = 0; j < common; j++) {
|
var oldLine = oldLines[j];
|
||||||
oldLine = oldLines[j];
|
var newLine = newLines[j];
|
||||||
newLine = newLines[j];
|
|
||||||
|
|
||||||
config.isCombined = file.isCombined;
|
config.isCombined = file.isCombined;
|
||||||
|
|
||||||
|
|
@ -131,17 +133,21 @@
|
||||||
generateSingleLineHtml(insertType, newLine.newNumber,
|
generateSingleLineHtml(insertType, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max > common) {
|
if (max > common) {
|
||||||
var oldSlice = oldLines.slice(common),
|
var oldSlice = oldLines.slice(common);
|
||||||
newSlice = newLines.slice(common);
|
var newSlice = newLines.slice(common);
|
||||||
tmpHtml = processLines(oldLines.slice(common), newLines.slice(common));
|
|
||||||
|
var tmpHtml = processLines(oldSlice, newSlice);
|
||||||
fileHtml.left += tmpHtml.left;
|
fileHtml.left += tmpHtml.left;
|
||||||
fileHtml.right += tmpHtml.right;
|
fileHtml.right += tmpHtml.right;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
newLines = [];
|
newLines = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < block.lines.length; i++) {
|
for (var i = 0; i < block.lines.length; i++) {
|
||||||
var line = block.lines[i];
|
var line = block.lines[i];
|
||||||
var prefix = line[0];
|
var prefix = line[0];
|
||||||
|
|
@ -151,15 +157,16 @@
|
||||||
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
(newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) {
|
||||||
processChangeBlock();
|
processChangeBlock();
|
||||||
}
|
}
|
||||||
if (line.type == diffParser.LINE_TYPE.CONTEXT) {
|
|
||||||
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
||||||
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
newLines.push(line);
|
newLines.push(line);
|
||||||
} else {
|
} else {
|
||||||
console.error('unknown state in html side-by-side generator');
|
console.error('unknown state in html side-by-side generator');
|
||||||
|
|
@ -179,21 +186,24 @@
|
||||||
fileHtml.right = '';
|
fileHtml.right = '';
|
||||||
|
|
||||||
var maxLinesNumber = Math.max(oldLines.length, newLines.length);
|
var maxLinesNumber = Math.max(oldLines.length, newLines.length);
|
||||||
for (j = 0; j < maxLinesNumber; j++) {
|
for (var i = 0; i < maxLinesNumber; i++) {
|
||||||
var oldLine = oldLines[j];
|
var oldLine = oldLines[i];
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[i];
|
||||||
var oldContent;
|
var oldContent;
|
||||||
var newContent;
|
var newContent;
|
||||||
var oldPrefix;
|
var oldPrefix;
|
||||||
var newPrefix;
|
var newPrefix;
|
||||||
|
|
||||||
if (oldLine) {
|
if (oldLine) {
|
||||||
oldContent = utils.escape(oldLine.content.substr(1));
|
oldContent = utils.escape(oldLine.content.substr(1));
|
||||||
oldPrefix = oldLine.content[0];
|
oldPrefix = oldLine.content[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newLine) {
|
if (newLine) {
|
||||||
newContent = utils.escape(newLine.content.substr(1));
|
newContent = utils.escape(newLine.content.substr(1));
|
||||||
newPrefix = newLine.content[0];
|
newPrefix = newLine.content[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldLine && newLine) {
|
if (oldLine && newLine) {
|
||||||
fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
|
|
@ -245,6 +255,6 @@
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports['SideBySidePrinter'] = new SideBySidePrinter();
|
module.exports.SideBySidePrinter = new SideBySidePrinter();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function(ctx, undefined) {
|
(function() {
|
||||||
|
|
||||||
function Utils() {
|
function Utils() {
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.getRandomId = function(prefix) {
|
Utils.prototype.getRandomId = function(prefix) {
|
||||||
return prefix + "-" + Math.random().toString(36).slice(-3);
|
return prefix + '-' + Math.random().toString(36).slice(-3);
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.startsWith = function(str, start) {
|
Utils.prototype.startsWith = function(str, start) {
|
||||||
|
|
@ -41,6 +41,6 @@
|
||||||
return value ? value : '';
|
return value ? value : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports['Utils'] = new Utils();
|
module.exports.Utils = new Utils();
|
||||||
|
|
||||||
})(this);
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue