From 4d3d7523618764aeca5dddd498e2acf4814e6a4d Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sun, 20 Dec 2015 22:22:26 +0000 Subject: [PATCH 1/3] Update contributors list, add codacy badge --- CREDITS.md | 2 ++ README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CREDITS.md b/CREDITS.md index 805096af..ae0694c5 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -17,3 +17,5 @@ Paulo Bu, [@pbu88](https://github.com/pbu88) Nuno Teixeira, [@nmatpt](https://github.com/nmatpt) Mikko Rantanen, [@Rantanen](https://github.com/Rantanen) + +Wolfgang Illmeyer, [@escitalopram](https://github.com/escitalopram) diff --git a/README.md b/README.md index dd5ef2b8..41298c4d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Diff to Html by [rtfpessoa](https://github.com/rtfpessoa) +[![Codacy Badge](https://api.codacy.com/project/badge/grade/06412dc3f5a14f568778d0db8a1f7dc8)](https://www.codacy.com/app/Codacy/diff2html) + Diff to Html generates pretty HTML diffs from git diff output. ## Features From 8d86a15d6900dd26995d72a17244943cf8ed2b13 Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sun, 20 Dec 2015 22:22:58 +0000 Subject: [PATCH 2/3] 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 --- dist/diff2html.js | 518 +++++++++++++++++++----------------- dist/diff2html.min.js | 4 +- src/diff-parser.js | 12 +- src/diff2html.js | 50 ++-- src/file-list-printer.js | 72 ++--- src/html-printer.js | 6 +- src/line-by-line-printer.js | 123 +++++---- src/printer-utils.js | 75 +++--- src/rematch.js | 92 ++++--- src/side-by-side-printer.js | 80 +++--- src/utils.js | 8 +- 11 files changed, 559 insertions(+), 481 deletions(-) diff --git a/dist/diff2html.js b/dist/diff2html.js index bfc292d5..6eaa477d 100644 --- a/dist/diff2html.js +++ b/dist/diff2html.js @@ -51,7 +51,7 @@ * */ - (function(ctx, undefined) { + (function() { var diffParser = __webpack_require__(1).DiffParser; var fileLister = __webpack_require__(3).FileListPrinter; @@ -63,9 +63,9 @@ /* * Line diff type configuration var config = { - "wordByWord": true, // (default) + 'wordByWord': true, // (default) // OR - "charByChar": true + 'charByChar': true }; */ @@ -83,23 +83,23 @@ var configOrEmpty = config || {}; var diffJson = diffInput; - if(!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') { + if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') { diffJson = diffParser.generateDiffJson(diffInput); } - var fileList = ""; - if(configOrEmpty.showFiles === true) { + var fileList = ''; + if (configOrEmpty.showFiles === true) { fileList = fileLister.generateFileList(diffJson, configOrEmpty); } - var diffOutput = ""; - if(configOrEmpty.outputFormat === 'side-by-side') { + var diffOutput = ''; + if (configOrEmpty.outputFormat === 'side-by-side') { diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); } else { diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); } - return fileList + diffOutput + return fileList + diffOutput; }; @@ -112,9 +112,9 @@ */ Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'diff'; - configOrEmpty['outputFormat'] = 'line-by-line'; - return this.getPrettyHtml(diffInput, configOrEmpty) + configOrEmpty.inputFormat = 'diff'; + configOrEmpty.outputFormat = 'line-by-line'; + return this.getPrettyHtml(diffInput, configOrEmpty); }; /* @@ -122,9 +122,9 @@ */ Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'json'; - configOrEmpty['outputFormat'] = 'line-by-line'; - return this.getPrettyHtml(diffJson, configOrEmpty) + configOrEmpty.inputFormat = 'json'; + configOrEmpty.outputFormat = 'line-by-line'; + return this.getPrettyHtml(diffJson, configOrEmpty); }; /* @@ -132,9 +132,9 @@ */ Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'diff'; - configOrEmpty['outputFormat'] = 'side-by-side'; - return this.getPrettyHtml(diffInput, configOrEmpty) + configOrEmpty.inputFormat = 'diff'; + configOrEmpty.outputFormat = 'side-by-side'; + return this.getPrettyHtml(diffInput, configOrEmpty); }; /* @@ -142,18 +142,18 @@ */ Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'json'; - configOrEmpty['outputFormat'] = 'side-by-side'; - return this.getPrettyHtml(diffJson, configOrEmpty) + configOrEmpty.inputFormat = 'json'; + configOrEmpty.outputFormat = 'side-by-side'; + return this.getPrettyHtml(diffJson, configOrEmpty); }; - var diffName = 'Diff2Html'; var diffObject = new Diff2Html(); - module.exports[diffName] = diffObject; + module.exports.Diff2Html = diffObject; + // Expose diff2html in the browser - global[diffName] = diffObject; + global.Diff2Html = diffObject; - })(this); + })(); /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) @@ -168,7 +168,7 @@ * */ - (function(ctx, undefined) { + (function() { var utils = __webpack_require__(2).Utils; @@ -194,6 +194,7 @@ var newLine = null; var saveBlock = function() { + /* Add previous block(if exists) before start a new file */ if (currentBlock) { currentFile.blocks.push(currentBlock); @@ -202,6 +203,7 @@ }; var saveFile = function() { + /* * Add previous file(if exists) before start a new one * if it has name (to avoid binary files errors) @@ -379,14 +381,14 @@ var nameSplit = filename.split('.'); if (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() { } @@ -414,7 +416,7 @@ }; 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) { @@ -436,9 +438,9 @@ return value ? value : ''; }; - module.exports['Utils'] = new Utils(); + module.exports.Utils = new Utils(); - })(this); + })(); /***/ }, @@ -452,42 +454,42 @@ * */ - (function (ctx, undefined) { + (function() { - var printerUtils = __webpack_require__(4).PrinterUtils; - var utils = __webpack_require__(2).Utils; + var printerUtils = __webpack_require__(4).PrinterUtils; + var utils = __webpack_require__(2).Utils; - function FileListPrinter() { - } + function FileListPrinter() { + } - FileListPrinter.prototype.generateFileList = function (diffFiles) { - var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page - var showId = utils.getRandomId("d2h-show"); - return '
\n' + - '
Files changed (' + diffFiles.length + ')  
\n' + - ' +\n' + - ' -\n' + - '
\n' + - ' \n' + - - - diffFiles.map(function (file) { - return ' \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' - }).join('\n') + - '
\n' + - ' +' + file.addedLines + '\n' + - ' \n' + - ' -' + file.deletedLines + '\n' + - '  ' + printerUtils.getDiffName(file) + '
\n'; - }; + FileListPrinter.prototype.generateFileList = function(diffFiles) { + var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page + var showId = utils.getRandomId('d2h-show'); + return '
\n' + + '
Files changed (' + diffFiles.length + ')  
\n' + + ' +\n' + + ' -\n' + + '
\n' + + ' \n' + + + + diffFiles.map(function(file) { + return ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n'; + }).join('\n') + + '
\n' + + ' +' + file.addedLines + '\n' + + ' \n' + + ' -' + file.deletedLines + '\n' + + '  ' + printerUtils.getDiffName(file) + '
\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 utils = __webpack_require__(2).Utils; @@ -511,39 +513,41 @@ } PrinterUtils.prototype.getHtmlId = function(file) { - var hashCode = function(text) { - var hash = 0, i, chr, len; - if (text.length == 0) return hash; + var hashCode = function(text) { + var i, chr, len; + var hash = 0; + + if (text.length === 0) return hash; + for (i = 0, len = text.length; i < len; i++) { - chr = text.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; + chr = text.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } + 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) { var oldFilename = file.oldName; var newFilename = file.newName; - if (oldFilename && newFilename - && oldFilename !== newFilename - && !isDeletedName(newFilename)) { + if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) { return oldFilename + ' -> ' + newFilename; } else if (newFilename && !isDeletedName(newFilename)) { return newFilename; } else if (oldFilename) { return oldFilename; - } else { - return 'Unknown filename'; } + + return 'Unknown filename'; }; PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) { - var lineStart1, lineStart2; + var linePrefix1, linePrefix2, unprefixedLine1, unprefixedLine2; var prefixSize = 1; @@ -551,17 +555,16 @@ prefixSize = 2; } - lineStart1 = diffLine1.substr(0, prefixSize); - lineStart2 = diffLine2.substr(0, prefixSize); - - diffLine1 = diffLine1.substr(prefixSize); - diffLine2 = diffLine2.substr(prefixSize); + linePrefix1 = diffLine1.substr(0, prefixSize); + linePrefix2 = diffLine2.substr(0, prefixSize); + unprefixedLine1 = diffLine1.substr(prefixSize); + unprefixedLine2 = diffLine2.substr(prefixSize); var diff; if (config.charByChar) { - diff = jsDiff.diffChars(diffLine1, diffLine2); + diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2); } else { - diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); + diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2); } var highlightedLine = ''; @@ -569,25 +572,30 @@ var changedWords = []; if (!config.charByChar && config.matching === 'words') { var treshold = 0.25; - if (typeof(config.matchWordsThreshold) !== "undefined") { + + if (typeof(config.matchWordsThreshold) !== 'undefined') { treshold = config.matchWordsThreshold; } + var matcher = Rematch.rematch(function(a, b) { - var amod = a.value, - bmod = b.value, - result = Rematch.distance(amod, bmod); - return result; + var amod = a.value; + var bmod = b.value; + + return Rematch.distance(amod, bmod); }); - var removed = diff.filter(function isRemoved(element){ + + var removed = diff.filter(function isRemoved(element) { return element.removed; }); - var added = diff.filter(function isAdded(element){ + + var added = diff.filter(function isAdded(element) { return element.added; }); + var chunks = matcher(added, removed); - chunks = chunks.forEach(function(chunk){ - if(chunk[0].length === 1 && chunk[1].length === 1) { - var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value) + chunks.forEach(function(chunk) { + if (chunk[0].length === 1 && chunk[1].length === 1) { + var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value); if (dist < treshold) { changedWords.push(chunk[0][0]); changedWords.push(chunk[1][0]); @@ -595,6 +603,7 @@ } }); } + diff.forEach(function(part) { var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; var elemType = part.added ? 'ins' : part.removed ? 'del' : null; @@ -609,11 +618,11 @@ return { first: { - prefix: lineStart1, + prefix: linePrefix1, line: removeIns(highlightedLine) }, second: { - prefix: lineStart2, + prefix: linePrefix2, line: removeDel(highlightedLine) } } @@ -631,9 +640,9 @@ return line.replace(/(]*>((.|\n)*?)<\/del>)/g, ''); } - module.exports['PrinterUtils'] = new PrinterUtils(); + module.exports.PrinterUtils = new PrinterUtils(); - })(this); + })(); /***/ }, @@ -1892,72 +1901,76 @@ * */ - (function(ctx, undefined) { + (function() { + var Rematch = {}; Rematch.arrayToString = function arrayToString(a) { - if (Object.prototype.toString.apply(a,[]) === "[object Array]") { + if (Object.prototype.toString.apply(a, []) === "[object Array]") { return "[" + a.map(arrayToString).join(", ") + "]"; } else { return a; } - } + }; /* - Copyright (c) 2011 Andrei Mackenzie - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - function levenshtein(a, b){ - if(a.length == 0) return b.length; - if(b.length == 0) return a.length; + Copyright (c) 2011 Andrei Mackenzie + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + function levenshtein(a, b) { + if (a.length == 0) return b.length; + if (b.length == 0) return a.length; var matrix = []; // increment along the first column of each row var i; - for(i = 0; i <= b.length; i++){ + for (i = 0; i <= b.length; i++) { matrix[i] = [i]; } // increment each column in the first row var j; - for(j = 0; j <= a.length; j++){ + for (j = 0; j <= a.length; j++) { matrix[0][j] = j; } // Fill in the rest of the matrix - for(i = 1; i <= b.length; i++){ - for(j = 1; j <= a.length; j++){ - if(b.charAt(i-1) == a.charAt(j-1)){ - matrix[i][j] = matrix[i-1][j-1]; + for (i = 1; i <= b.length; i++) { + for (j = 1; j <= a.length; j++) { + if (b.charAt(i - 1) == a.charAt(j - 1)) { + matrix[i][j] = matrix[i - 1][j - 1]; } else { - matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution - Math.min(matrix[i][j-1] + 1, // insertion - matrix[i-1][j] + 1)); // deletion + matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution + Math.min(matrix[i][j - 1] + 1, // insertion + matrix[i - 1][j] + 1)); // deletion } } } + return matrix[b.length][a.length]; } + Rematch.levenshtein = levenshtein; - Rematch.distance = function distance(x,y) { - x=x.trim(); - y=y.trim(); - var lev = levenshtein(x,y), - score = lev / (x.length + y.length); + Rematch.distance = function distance(x, y) { + x = x.trim(); + y = y.trim(); + var lev = levenshtein(x, y); + var score = lev / (x.length + y.length); + return score; - } + }; Rematch.rematch = function rematch(distanceFunction) { - function findBestMatch(a, b, cache) { var cachecount = 0; - for(var key in cache) { + for (var key in cache) { cachecount++; } + var bestMatchDist = Infinity; var bestMatch; for (var i = 0; i < a.length; ++i) { @@ -1972,25 +1985,29 @@ } if (md < bestMatchDist) { bestMatchDist = md; - bestMatch = { indexA: i, indexB: j, score: bestMatchDist }; + bestMatch = {indexA: i, indexB: j, score: bestMatchDist}; } } } + return bestMatch; } - function group(a, b, level, cache) { - if (typeof(cache)==="undefined") { + function group(a, b, level, cache) { + if (typeof(cache) === "undefined") { cache = {}; } - var minLength = Math.min(a.length, b.length); - var bm = findBestMatch(a,b, cache); + + var bm = findBestMatch(a, b, cache); + if (!level) { level = 0; } + if (!bm || (a.length + b.length < 3)) { return [[a, b]]; } + var a1 = a.slice(0, bm.indexA), b1 = b.slice(0, bm.indexB), aMatch = [a[bm.indexA]], @@ -2000,24 +2017,28 @@ a2 = a.slice(tailA), b2 = b.slice(tailB); - var group1 = group(a1, b1, level+1, cache); - var groupMatch = group(aMatch, bMatch, level+1, cache); - var group2 = group(a2, b2, level+1, cache); + var group1 = group(a1, b1, level + 1, cache); + var groupMatch = group(aMatch, bMatch, level + 1, cache); + var group2 = group(a2, b2, level + 1, cache); var result = groupMatch; + if (bm.indexA > 0 || bm.indexB > 0) { result = group1.concat(result); } - if (a.length > tailA || b.length > tailB ) { + + if (a.length > tailA || b.length > tailB) { result = result.concat(group2); } + return result; } + 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; 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; - 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 printerUtils = __webpack_require__(4).PrinterUtils; var utils = __webpack_require__(2).Utils; 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 '
\n' + diffFiles.map(function(file) { var diffs; if (file.blocks.length) { - diffs = generateFileHtml(file, config); + diffs = that._generateFileHtml(file); } else { - diffs = generateEmptyDiff(); + diffs = that._generateEmptyDiff(); } return '
\n' + @@ -2106,13 +2132,15 @@ '
\n'; }; - var matcher=Rematch.rematch(function(a,b) { - var amod = a.content.substr(1), - bmod = b.content.substr(1); + var matcher = Rematch.rematch(function(a, b) { + var amod = a.content.substr(1); + var bmod = b.content.substr(1); + return Rematch.distance(amod, bmod); }); - function generateFileHtml(file, config) { + LineByLinePrinter.prototype._generateFileHtml = function(file) { + var that = this; return file.blocks.map(function(block) { var lines = '\n' + @@ -2124,50 +2152,53 @@ var oldLines = []; var newLines = []; + function processChangeBlock() { var matches; var insertType; var deleteType; - var doMatching = config.matching === "lines" || config.matching === "words"; + + var doMatching = that.config.matching === 'lines' || that.config.matching === 'words'; + if (doMatching) { matches = matcher(oldLines, newLines); insertType = diffParser.LINE_TYPE.INSERT_CHANGES; deleteType = diffParser.LINE_TYPE.DELETE_CHANGES; } else { - matches = [[oldLines,newLines]]; + matches = [[oldLines, newLines]]; insertType = diffParser.LINE_TYPE.INSERTS; deleteType = diffParser.LINE_TYPE.DELETES; } - matches.forEach(function(match){ - var oldLines = match[0]; - var newLines = match[1]; + + matches.forEach(function(match) { + oldLines = match[0]; + newLines = match[1]; + var processedOldLines = []; var processedNewLines = []; - var j = 0; - var oldLine, newLine, - common = Math.min(oldLines.length, newLines.length), - max = Math.max(oldLines.length, newLines.length); - for (j = 0; j < common; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; - - config.isCombined = file.isCombined; - var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); - - processedOldLines += - generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber, - diff.first.line, diff.first.prefix); - processedNewLines += - generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber, - diff.second.line, diff.second.prefix); - } - lines += processedOldLines + processedNewLines; - lines += processLines(oldLines.slice(common), newLines.slice(common)); + var common = Math.min(oldLines.length, newLines.length); + + var oldLine, newLine; + for (var j = 0; j < common; j++) { + oldLine = oldLines[j]; + newLine = newLines[j]; + + that.config.isCombined = file.isCombined; + var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config); - processedOldLines = []; - processedNewLines = []; + processedOldLines += + that._generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber, + diff.first.line, diff.first.prefix); + processedNewLines += + that._generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber, + diff.second.line, diff.second.prefix); + } + + lines += processedOldLines + processedNewLines; + lines += that._processLines(oldLines.slice(common), newLines.slice(common)); }); + oldLines = []; newLines = []; } @@ -2176,20 +2207,21 @@ var line = block.lines[i]; var escapedLine = utils.escape(line.content); - if ( line.type !== diffParser.LINE_TYPE.INSERTS && - (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { + if (line.type !== diffParser.LINE_TYPE.INSERTS && + (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { processChangeBlock(); } - if (line.type == diffParser.LINE_TYPE.CONTEXT) { - lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) { - lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.DELETES) { + + if (line.type === diffParser.LINE_TYPE.CONTEXT) { + lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) { + lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type === diffParser.LINE_TYPE.DELETES) { 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); } else { - console.error('unknown state in html line-by-line generator'); + console.error('Unknown state in html line-by-line generator'); processChangeBlock(); } } @@ -2198,27 +2230,27 @@ return lines; }).join('\n'); - } + }; - function processLines(oldLines, newLines) { + LineByLinePrinter.prototype._processLines = function(oldLines, newLines) { var lines = ''; - for (j = 0; j < oldLines.length; j++) { - var oldLine = oldLines[j]; + for (var i = 0; i < oldLines.length; i++) { + var oldLine = oldLines[i]; 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 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; - } + }; - function generateLineHtml(type, oldNumber, newNumber, content, prefix) { + LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) { var htmlPrefix = ''; if (prefix) { htmlPrefix = '' + prefix + ''; @@ -2238,9 +2270,9 @@ '
' + htmlPrefix + htmlContent + '
' + ' \n' + '\n'; - } + }; - function generateEmptyDiff() { + LineByLinePrinter.prototype._generateEmptyDiff = function() { return '\n' + ' ' + '
' + @@ -2248,11 +2280,11 @@ '
' + ' \n' + '\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 printerUtils = __webpack_require__(4).PrinterUtils; @@ -2324,9 +2356,9 @@ '
\n'; }; - var matcher=Rematch.rematch(function(a,b) { + var matcher = Rematch.rematch(function(a, b) { var amod = a.content.substr(1), - bmod = b.content.substr(1); + bmod = b.content.substr(1); return Rematch.distance(amod, bmod); }); @@ -2355,31 +2387,33 @@ var oldLines = []; var newLines = []; + function processChangeBlock() { var matches; var insertType; var deleteType; - var doMatching = config.matching === "lines" || config.matching === "words"; + var doMatching = config.matching === 'lines' || config.matching === 'words'; + if (doMatching) { matches = matcher(oldLines, newLines); insertType = diffParser.LINE_TYPE.INSERT_CHANGES; deleteType = diffParser.LINE_TYPE.DELETE_CHANGES; } else { - matches = [[oldLines,newLines]]; + matches = [[oldLines, newLines]]; insertType = diffParser.LINE_TYPE.INSERTS; deleteType = diffParser.LINE_TYPE.DELETES; } - matches.forEach(function(match){ - var oldLines = match[0]; - var newLines = match[1]; - var tmpHtml; - var j = 0; - var oldLine, newLine, - common = Math.min(oldLines.length, newLines.length), - max = Math.max(oldLines.length, newLines.length); - for (j = 0; j < common; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; + + matches.forEach(function(match) { + oldLines = match[0]; + newLines = match[1]; + + var common = Math.min(oldLines.length, newLines.length); + var max = Math.max(oldLines.length, newLines.length); + + for (var j = 0; j < common; j++) { + var oldLine = oldLines[j]; + var newLine = newLines[j]; config.isCombined = file.isCombined; @@ -2391,36 +2425,41 @@ fileHtml.right += generateSingleLineHtml(insertType, newLine.newNumber, diff.second.line, diff.second.prefix); - } - if (max > common) { - var oldSlice = oldLines.slice(common), - newSlice = newLines.slice(common); - tmpHtml = processLines(oldLines.slice(common), newLines.slice(common)); - fileHtml.left += tmpHtml.left; - fileHtml.right += tmpHtml.right; - } + } + + if (max > common) { + var oldSlice = oldLines.slice(common); + var newSlice = newLines.slice(common); + + var tmpHtml = processLines(oldSlice, newSlice); + fileHtml.left += tmpHtml.left; + fileHtml.right += tmpHtml.right; + } }); + oldLines = []; newLines = []; } + for (var i = 0; i < block.lines.length; i++) { var line = block.lines[i]; var prefix = line[0]; var escapedLine = utils.escape(line.content.substr(1)); - if ( line.type !== diffParser.LINE_TYPE.INSERTS && - (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { + if (line.type !== diffParser.LINE_TYPE.INSERTS && + (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { 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.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.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); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) { + } else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) { newLines.push(line); } else { console.error('unknown state in html side-by-side generator'); @@ -2440,21 +2479,24 @@ fileHtml.right = ''; var maxLinesNumber = Math.max(oldLines.length, newLines.length); - for (j = 0; j < maxLinesNumber; j++) { - var oldLine = oldLines[j]; - var newLine = newLines[j]; + for (var i = 0; i < maxLinesNumber; i++) { + var oldLine = oldLines[i]; + var newLine = newLines[i]; var oldContent; var newContent; var oldPrefix; var newPrefix; + if (oldLine) { oldContent = utils.escape(oldLine.content.substr(1)); oldPrefix = oldLine.content[0]; } + if (newLine) { newContent = utils.escape(newLine.content.substr(1)); newPrefix = newLine.content[0]; } + if (oldLine && newLine) { fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix); @@ -2506,9 +2548,9 @@ return fileHtml; } - module.exports['SideBySidePrinter'] = new SideBySidePrinter(); + module.exports.SideBySidePrinter = new SideBySidePrinter(); - })(this); + })(); /***/ } diff --git a/dist/diff2html.min.js b/dist/diff2html.min.js index 39a7aa64..82dbdb3f 100644 --- a/dist/diff2html.min.js +++ b/dist/diff2html.min.js @@ -1,3 +1,3 @@ -!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){(function(global){!function(){function Diff2Html(){}var diffParser=__webpack_require__(1).DiffParser,fileLister=__webpack_require__(3).FileListPrinter,htmlPrinter=__webpack_require__(21).HtmlPrinter;Diff2Html.prototype.getJsonFromDiff=function(diffInput){return diffParser.generateDiffJson(diffInput)},Diff2Html.prototype.getPrettyHtml=function(diffInput,config){var configOrEmpty=config||{},diffJson=diffInput;configOrEmpty.inputFormat&&"diff"!==configOrEmpty.inputFormat||(diffJson=diffParser.generateDiffJson(diffInput));var fileList="";configOrEmpty.showFiles===!0&&(fileList=fileLister.generateFileList(diffJson,configOrEmpty));var diffOutput="";return diffOutput="side-by-side"===configOrEmpty.outputFormat?htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty):htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty),fileList+diffOutput},Diff2Html.prototype.getPrettyHtmlFromDiff=function(diffInput,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="diff",configOrEmpty.outputFormat="line-by-line",this.getPrettyHtml(diffInput,configOrEmpty)},Diff2Html.prototype.getPrettyHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="json",configOrEmpty.outputFormat="line-by-line",this.getPrettyHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromDiff=function(diffInput,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="diff",configOrEmpty.outputFormat="side-by-side",this.getPrettyHtml(diffInput,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="json",configOrEmpty.outputFormat="side-by-side",this.getPrettyHtml(diffJson,configOrEmpty)};var diffName="Diff2Html",diffObject=new Diff2Html;module.exports[diffName]=diffObject,global[diffName]=diffObject}(this)}).call(exports,function(){return this}())},function(module,exports,__webpack_require__){!function(){function DiffParser(){}function getExtension(filename,language){var nameSplit=filename.split(".");return nameSplit.length>1?nameSplit[nameSplit.length-1]:language}var utils=__webpack_require__(2).Utils,LINE_TYPE={INSERTS:"d2h-ins",DELETES:"d2h-del",INSERT_CHANGES:"d2h-ins d2h-change",DELETE_CHANGES:"d2h-del d2h-change",CONTEXT:"d2h-cntx",INFO:"d2h-info"};DiffParser.prototype.LINE_TYPE=LINE_TYPE,DiffParser.prototype.generateDiffJson=function(diffInput){var files=[],currentFile=null,currentBlock=null,oldLine=null,newLine=null,saveBlock=function(){currentBlock&&(currentFile.blocks.push(currentBlock),currentBlock=null)},saveFile=function(){currentFile&¤tFile.newName&&(files.push(currentFile),currentFile=null)},startFile=function(){saveBlock(),saveFile(),currentFile={},currentFile.blocks=[],currentFile.deletedLines=0,currentFile.addedLines=0},startBlock=function(line){saveBlock();var values;(values=/^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line))?currentFile.isCombined=!1:(values=/^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line))?currentFile.isCombined=!0:(values=[0,0],currentFile.isCombined=!1),oldLine=values[1],newLine=values[2],currentBlock={},currentBlock.lines=[],currentBlock.oldStartLine=oldLine,currentBlock.newStartLine=newLine,currentBlock.header=line},createLine=function(line){var currentLine={};currentLine.content=line;var newLinePrefixes=currentFile.isCombined?["+"," +"]:["+"],delLinePrefixes=currentFile.isCombined?["-"," -"]:["-"];utils.startsWith(line,newLinePrefixes)?(currentFile.addedLines++,currentLine.type=LINE_TYPE.INSERTS,currentLine.oldNumber=null,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine)):utils.startsWith(line,delLinePrefixes)?(currentFile.deletedLines++,currentLine.type=LINE_TYPE.DELETES,currentLine.oldNumber=oldLine++,currentLine.newNumber=null,currentBlock.lines.push(currentLine)):(currentLine.type=LINE_TYPE.CONTEXT,currentLine.oldNumber=oldLine++,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine))},diffLines=diffInput.split("\n"),oldMode=/^old mode (\d{6})/,newMode=/^new mode (\d{6})/,deletedFileMode=/^deleted file mode (\d{6})/,newFileMode=/^new file mode (\d{6})/,copyFrom=/^copy from (.+)/,copyTo=/^copy to (.+)/,renameFrom=/^rename from (.+)/,renameTo=/^rename to (.+)/,similarityIndex=/^similarity index (\d+)%/,dissimilarityIndex=/^dissimilarity index (\d+)%/,index=/^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/,combinedIndex=/^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/,combinedMode=/^mode (\d{6}),(\d{6})..(\d{6})/,combinedNewFile=/^new file mode (\d{6})/,combinedDeletedFile=/^deleted file mode (\d{6}),(\d{6})/;return diffLines.forEach(function(line){if(line&&!utils.startsWith(line,"*")){var values=[];utils.startsWith(line,"diff")?startFile():currentFile&&!currentFile.oldName&&(values=/^--- [aiwco]\/(.+)$/.exec(line))?(currentFile.oldName=values[1],currentFile.language=getExtension(currentFile.oldName,currentFile.language)):currentFile&&!currentFile.newName&&(values=/^\+\+\+ [biwco]?\/(.+)$/.exec(line))?(currentFile.newName=values[1],currentFile.language=getExtension(currentFile.newName,currentFile.language)):currentFile&&utils.startsWith(line,"@@")?startBlock(line):(values=oldMode.exec(line))?currentFile.oldMode=values[1]:(values=newMode.exec(line))?currentFile.newMode=values[1]:(values=deletedFileMode.exec(line))?currentFile.deletedFileMode=values[1]:(values=newFileMode.exec(line))?currentFile.newFileMode=values[1]:(values=copyFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isCopy=!0):(values=copyTo.exec(line))?(currentFile.newName=values[1],currentFile.isCopy=!0):(values=renameFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isRename=!0):(values=renameTo.exec(line))?(currentFile.newName=values[1],currentFile.isRename=!0):(values=similarityIndex.exec(line))?currentFile.unchangedPercentage=values[1]:(values=dissimilarityIndex.exec(line))?currentFile.changedPercentage=values[1]:(values=index.exec(line))?(currentFile.checksumBefore=values[1],currentFile.checksumAfter=values[2],values[2]&&(currentFile.mode=values[3])):(values=combinedIndex.exec(line))?(currentFile.checksumBefore=[values[2],values[3]],currentFile.checksumAfter=values[1]):(values=combinedMode.exec(line))?(currentFile.oldMode=[values[2],values[3]],currentFile.newMode=values[1]):(values=combinedNewFile.exec(line))?currentFile.newFileMode=values[1]:(values=combinedDeletedFile.exec(line))?currentFile.deletedFileMode=values[1]:currentBlock&&createLine(line)}}),saveBlock(),saveFile(),files},module.exports.DiffParser=new DiffParser}(this)},function(module){!function(){function Utils(){}Utils.prototype.escape=function(str){return str.slice(0).replace(/&/g,"&").replace(//g,">").replace(/\t/g," ")},Utils.prototype.getRandomId=function(prefix){return prefix+"-"+Math.random().toString(36).slice(-3)},Utils.prototype.startsWith=function(str,start){if("object"==typeof start){var result=!1;return start.forEach(function(s){0===str.indexOf(s)&&(result=!0)}),result}return 0===str.indexOf(start)},Utils.prototype.valueOrEmpty=function(value){return value?value:""},module.exports.Utils=new Utils}(this)},function(module,exports,__webpack_require__){!function(){function FileListPrinter(){}var printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils;FileListPrinter.prototype.generateFileList=function(diffFiles){var hideId=utils.getRandomId("d2h-hide"),showId=utils.getRandomId("d2h-show");return'
\n
Files changed ('+diffFiles.length+')  
\n +\n -\n
\n \n'+diffFiles.map(function(file){return' \n \n \n \n \n"}).join("\n")+"
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n  '+printerUtils.getDiffName(file)+"
\n"},module.exports.FileListPrinter=new FileListPrinter}(this)},function(module,exports,__webpack_require__){!function(){function PrinterUtils(){}function isDeletedName(name){return"dev/null"===name}function removeIns(line){return line.replace(/(]*>((.|\n)*?)<\/ins>)/g,"")}function removeDel(line){return line.replace(/(]*>((.|\n)*?)<\/del>)/g,"")}var jsDiff=__webpack_require__(5),utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;PrinterUtils.prototype.getHtmlId=function(file){var hashCode=function(text){var i,chr,len,hash=0;if(0==text.length)return hash;for(i=0,len=text.length;len>i;i++)chr=text.charCodeAt(i),hash=(hash<<5)-hash+chr,hash|=0;return hash};return"d2h-"+hashCode(this.getDiffName(file)).toString().slice(-6)},PrinterUtils.prototype.getDiffName=function(file){var oldFilename=file.oldName,newFilename=file.newName;return oldFilename&&newFilename&&oldFilename!==newFilename&&!isDeletedName(newFilename)?oldFilename+" -> "+newFilename:newFilename&&!isDeletedName(newFilename)?newFilename:oldFilename?oldFilename:"Unknown filename"},PrinterUtils.prototype.diffHighlight=function(diffLine1,diffLine2,config){var lineStart1,lineStart2,prefixSize=1;config.isCombined&&(prefixSize=2),lineStart1=diffLine1.substr(0,prefixSize),lineStart2=diffLine2.substr(0,prefixSize),diffLine1=diffLine1.substr(prefixSize),diffLine2=diffLine2.substr(prefixSize);var diff;diff=config.charByChar?jsDiff.diffChars(diffLine1,diffLine2):jsDiff.diffWordsWithSpace(diffLine1,diffLine2);var highlightedLine="",changedWords=[];if(!config.charByChar&&"words"===config.matching){var treshold=.25;"undefined"!=typeof config.matchWordsThreshold&&(treshold=config.matchWordsThreshold);var matcher=Rematch.rematch(function(a,b){var amod=a.value,bmod=b.value,result=Rematch.distance(amod,bmod);return result}),removed=diff.filter(function(element){return element.removed}),added=diff.filter(function(element){return element.added}),chunks=matcher(added,removed);chunks=chunks.forEach(function(chunk){if(1===chunk[0].length&&1===chunk[1].length){var dist=Rematch.distance(chunk[0][0].value,chunk[1][0].value);treshold>dist&&(changedWords.push(chunk[0][0]),changedWords.push(chunk[1][0]))}})}return diff.forEach(function(part){var addClass=changedWords.indexOf(part)>-1?' class="d2h-change"':"",elemType=part.added?"ins":part.removed?"del":null,escapedValue=utils.escape(part.value);highlightedLine+=null!==elemType?"<"+elemType+addClass+">"+escapedValue+"":escapedValue}),{first:{prefix:lineStart1,line:removeIns(highlightedLine)},second:{prefix:lineStart2,line:removeDel(highlightedLine)}}},module.exports.PrinterUtils=new PrinterUtils}(this)},function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}exports.__esModule=!0;var _diffBase=__webpack_require__(6),_diffBase2=_interopRequireDefault(_diffBase),_diffCharacter=__webpack_require__(7),_diffWord=__webpack_require__(8),_diffLine=__webpack_require__(10),_diffSentence=__webpack_require__(11),_diffCss=__webpack_require__(12),_diffJson=__webpack_require__(13),_patchApply=__webpack_require__(14),_patchParse=__webpack_require__(15),_patchCreate=__webpack_require__(17),_convertDmp=__webpack_require__(18),_convertXml=__webpack_require__(19);exports.Diff=_diffBase2["default"],exports.diffChars=_diffCharacter.diffChars,exports.diffWords=_diffWord.diffWords,exports.diffWordsWithSpace=_diffWord.diffWordsWithSpace,exports.diffLines=_diffLine.diffLines,exports.diffTrimmedLines=_diffLine.diffTrimmedLines,exports.diffSentences=_diffSentence.diffSentences,exports.diffCss=_diffCss.diffCss,exports.diffJson=_diffJson.diffJson,exports.structuredPatch=_patchCreate.structuredPatch,exports.createTwoFilesPatch=_patchCreate.createTwoFilesPatch,exports.createPatch=_patchCreate.createPatch,exports.applyPatch=_patchApply.applyPatch,exports.applyPatches=_patchApply.applyPatches,exports.parsePatch=_patchParse.parsePatch,exports.convertChangesToDMP=_convertDmp.convertChangesToDMP,exports.convertChangesToXML=_convertXml.convertChangesToXML,exports.canonicalize=_diffJson.canonicalize},function(module,exports){"use strict";function Diff(){}function buildValues(diff,components,newString,oldString,useLongestToken){for(var componentPos=0,componentLen=components.length,newPos=0,oldPos=0;componentLen>componentPos;componentPos++){var component=components[componentPos];if(component.removed){if(component.value=oldString.slice(oldPos,oldPos+component.count).join(""),oldPos+=component.count,componentPos&&components[componentPos-1].added){var tmp=components[componentPos-1];components[componentPos-1]=components[componentPos],components[componentPos]=tmp}}else{if(!component.added&&useLongestToken){var value=newString.slice(newPos,newPos+component.count);value=value.map(function(value,i){var oldValue=oldString[oldPos+i];return oldValue.length>value.length?oldValue:value}),component.value=value.join("")}else component.value=newString.slice(newPos,newPos+component.count).join("");newPos+=component.count,component.added||(oldPos+=component.count)}}var lastComponent=components[componentLen-1];return(lastComponent.added||lastComponent.removed)&&diff.equals("",lastComponent.value)&&(components[componentLen-2].value+=lastComponent.value,components.pop()),components}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}exports.__esModule=!0,exports["default"]=Diff,Diff.prototype={diff:function(oldString,newString){function done(value){return callback?(setTimeout(function(){callback(void 0,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath=void 0,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1],_oldPos=(removePath?removePath.newPos:0)-diagonalPath;addPath&&(bestPath[diagonalPath-1]=void 0);var canAdd=addPath&&addPath.newPos+1=0&&oldLen>_oldPos;if(canAdd||canRemove){if(!canAdd||canRemove&&addPath.newPos=newLen&&_oldPos+1>=oldLen)return done(buildValues(self,basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=void 0}editLength++}var options=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],callback=options.callback;"function"==typeof options&&(callback=options,options={}),this.options=options;var self=this;oldString=this.castInput(oldString),newString=this.castInput(newString),oldString=this.removeEmpty(this.tokenize(oldString)),newString=this.removeEmpty(this.tokenize(newString));var newLen=newString.length,oldLen=oldString.length,editLength=1,maxEditLength=newLen+oldLen,bestPath=[{newPos:-1,components:[]}],oldPos=this.extractCommon(bestPath[0],newString,oldString,0);if(bestPath[0].newPos+1>=newLen&&oldPos+1>=oldLen)return done([{value:newString.join(""),count:newString.length}]);if(callback)!function exec(){setTimeout(function(){return editLength>maxEditLength?callback():void(execEditLength()||exec())},0)}();else for(;maxEditLength>=editLength;){var ret=execEditLength();if(ret)return ret}},pushComponent:function(components,added,removed){var last=components[components.length-1];last&&last.added===added&&last.removed===removed?components[components.length-1]={count:last.count+1,added:added,removed:removed}:components.push({count:1,added:added,removed:removed})},extractCommon:function(basePath,newString,oldString,diagonalPath){for(var newLen=newString.length,oldLen=oldString.length,newPos=basePath.newPos,oldPos=newPos-diagonalPath,commonCount=0;newLen>newPos+1&&oldLen>oldPos+1&&this.equals(newString[newPos+1],oldString[oldPos+1]);)newPos++,oldPos++,commonCount++;return commonCount&&basePath.components.push({count:commonCount}),basePath.newPos=newPos,oldPos},equals:function(left,right){return left===right},removeEmpty:function(array){for(var ret=[],i=0;ifuzzFactor))return!1;toPos++}}return!0}var options=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof uniDiff&&(uniDiff=_parse.parsePatch(uniDiff)),Array.isArray(uniDiff)){if(uniDiff.length>1)throw new Error("applyPatch only works with a single input.");uniDiff=uniDiff[0]}for(var lines=source.split("\n"),hunks=uniDiff.hunks,compareLine=options.compareLine||function(lineNumber,line,operation,patchContent){return line===patchContent},errorCount=0,fuzzFactor=options.fuzzFactor||0,minLine=0,offset=0,removeEOFNL=void 0,addEOFNL=void 0,i=0;i=start+localOffset)return localOffset;forwardExhausted=!0}if(backwardExhausted);else{if(forwardExhausted||(wantForward=!0),start-localOffset>=minLine)return-localOffset++;backwardExhausted=!0,_again=!0}}}},module.exports=exports["default"]},function(module,exports,__webpack_require__){"use strict";function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i0?contextLines(prev.lines.slice(-options.context)):[],oldRangeStart-=curRange.length,newRangeStart-=curRange.length)}(_curRange=curRange).push.apply(_curRange,_toConsumableArray(lines.map(function(entry){return(current.added?"+":"-")+entry}))),current.added?newLine+=lines.length:oldLine+=lines.length}else{if(oldRangeStart)if(lines.length<=2*options.context&&i=diff.length-2&&lines.length<=options.context){var oldEOFNewline=/\n$/.test(oldStr),newEOFNewline=/\n$/.test(newStr);0!=lines.length||oldEOFNewline?oldEOFNewline&&newEOFNewline||curRange.push("\\ No newline at end of file"):curRange.splice(hunk.oldLines,0,"\\ No newline at end of file")}hunks.push(hunk),oldRangeStart=0,newRangeStart=0,curRange=[]}oldLine+=lines.length,newLine+=lines.length}},i=0;i"):change.removed&&ret.push(""),ret.push(escapeHTML(change.value)),change.added?ret.push(""):change.removed&&ret.push(""); +!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){(function(global){!function(){function Diff2Html(){}var diffParser=__webpack_require__(1).DiffParser,fileLister=__webpack_require__(3).FileListPrinter,htmlPrinter=__webpack_require__(21).HtmlPrinter;Diff2Html.prototype.getJsonFromDiff=function(diffInput){return diffParser.generateDiffJson(diffInput)},Diff2Html.prototype.getPrettyHtml=function(diffInput,config){var configOrEmpty=config||{},diffJson=diffInput;configOrEmpty.inputFormat&&"diff"!==configOrEmpty.inputFormat||(diffJson=diffParser.generateDiffJson(diffInput));var fileList="";configOrEmpty.showFiles===!0&&(fileList=fileLister.generateFileList(diffJson,configOrEmpty));var diffOutput="";return diffOutput="side-by-side"===configOrEmpty.outputFormat?htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty):htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty),fileList+diffOutput},Diff2Html.prototype.getPrettyHtmlFromDiff=function(diffInput,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="diff",configOrEmpty.outputFormat="line-by-line",this.getPrettyHtml(diffInput,configOrEmpty)},Diff2Html.prototype.getPrettyHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="json",configOrEmpty.outputFormat="line-by-line",this.getPrettyHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromDiff=function(diffInput,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="diff",configOrEmpty.outputFormat="side-by-side",this.getPrettyHtml(diffInput,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return configOrEmpty.inputFormat="json",configOrEmpty.outputFormat="side-by-side",this.getPrettyHtml(diffJson,configOrEmpty)};var diffObject=new Diff2Html;module.exports.Diff2Html=diffObject,global.Diff2Html=diffObject}()}).call(exports,function(){return this}())},function(module,exports,__webpack_require__){!function(){function DiffParser(){}function getExtension(filename,language){var nameSplit=filename.split(".");return nameSplit.length>1?nameSplit[nameSplit.length-1]:language}var utils=__webpack_require__(2).Utils,LINE_TYPE={INSERTS:"d2h-ins",DELETES:"d2h-del",INSERT_CHANGES:"d2h-ins d2h-change",DELETE_CHANGES:"d2h-del d2h-change",CONTEXT:"d2h-cntx",INFO:"d2h-info"};DiffParser.prototype.LINE_TYPE=LINE_TYPE,DiffParser.prototype.generateDiffJson=function(diffInput){var files=[],currentFile=null,currentBlock=null,oldLine=null,newLine=null,saveBlock=function(){currentBlock&&(currentFile.blocks.push(currentBlock),currentBlock=null)},saveFile=function(){currentFile&¤tFile.newName&&(files.push(currentFile),currentFile=null)},startFile=function(){saveBlock(),saveFile(),currentFile={},currentFile.blocks=[],currentFile.deletedLines=0,currentFile.addedLines=0},startBlock=function(line){saveBlock();var values;(values=/^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line))?currentFile.isCombined=!1:(values=/^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line))?currentFile.isCombined=!0:(values=[0,0],currentFile.isCombined=!1),oldLine=values[1],newLine=values[2],currentBlock={},currentBlock.lines=[],currentBlock.oldStartLine=oldLine,currentBlock.newStartLine=newLine,currentBlock.header=line},createLine=function(line){var currentLine={};currentLine.content=line;var newLinePrefixes=currentFile.isCombined?["+"," +"]:["+"],delLinePrefixes=currentFile.isCombined?["-"," -"]:["-"];utils.startsWith(line,newLinePrefixes)?(currentFile.addedLines++,currentLine.type=LINE_TYPE.INSERTS,currentLine.oldNumber=null,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine)):utils.startsWith(line,delLinePrefixes)?(currentFile.deletedLines++,currentLine.type=LINE_TYPE.DELETES,currentLine.oldNumber=oldLine++,currentLine.newNumber=null,currentBlock.lines.push(currentLine)):(currentLine.type=LINE_TYPE.CONTEXT,currentLine.oldNumber=oldLine++,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine))},diffLines=diffInput.split("\n"),oldMode=/^old mode (\d{6})/,newMode=/^new mode (\d{6})/,deletedFileMode=/^deleted file mode (\d{6})/,newFileMode=/^new file mode (\d{6})/,copyFrom=/^copy from (.+)/,copyTo=/^copy to (.+)/,renameFrom=/^rename from (.+)/,renameTo=/^rename to (.+)/,similarityIndex=/^similarity index (\d+)%/,dissimilarityIndex=/^dissimilarity index (\d+)%/,index=/^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/,combinedIndex=/^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/,combinedMode=/^mode (\d{6}),(\d{6})..(\d{6})/,combinedNewFile=/^new file mode (\d{6})/,combinedDeletedFile=/^deleted file mode (\d{6}),(\d{6})/;return diffLines.forEach(function(line){if(line&&!utils.startsWith(line,"*")){var values=[];utils.startsWith(line,"diff")?startFile():currentFile&&!currentFile.oldName&&(values=/^--- [aiwco]\/(.+)$/.exec(line))?(currentFile.oldName=values[1],currentFile.language=getExtension(currentFile.oldName,currentFile.language)):currentFile&&!currentFile.newName&&(values=/^\+\+\+ [biwco]?\/(.+)$/.exec(line))?(currentFile.newName=values[1],currentFile.language=getExtension(currentFile.newName,currentFile.language)):currentFile&&utils.startsWith(line,"@@")?startBlock(line):(values=oldMode.exec(line))?currentFile.oldMode=values[1]:(values=newMode.exec(line))?currentFile.newMode=values[1]:(values=deletedFileMode.exec(line))?currentFile.deletedFileMode=values[1]:(values=newFileMode.exec(line))?currentFile.newFileMode=values[1]:(values=copyFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isCopy=!0):(values=copyTo.exec(line))?(currentFile.newName=values[1],currentFile.isCopy=!0):(values=renameFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isRename=!0):(values=renameTo.exec(line))?(currentFile.newName=values[1],currentFile.isRename=!0):(values=similarityIndex.exec(line))?currentFile.unchangedPercentage=values[1]:(values=dissimilarityIndex.exec(line))?currentFile.changedPercentage=values[1]:(values=index.exec(line))?(currentFile.checksumBefore=values[1],currentFile.checksumAfter=values[2],values[2]&&(currentFile.mode=values[3])):(values=combinedIndex.exec(line))?(currentFile.checksumBefore=[values[2],values[3]],currentFile.checksumAfter=values[1]):(values=combinedMode.exec(line))?(currentFile.oldMode=[values[2],values[3]],currentFile.newMode=values[1]):(values=combinedNewFile.exec(line))?currentFile.newFileMode=values[1]:(values=combinedDeletedFile.exec(line))?currentFile.deletedFileMode=values[1]:currentBlock&&createLine(line)}}),saveBlock(),saveFile(),files},module.exports.DiffParser=new DiffParser}()},function(module){!function(){function Utils(){}Utils.prototype.escape=function(str){return str.slice(0).replace(/&/g,"&").replace(//g,">").replace(/\t/g," ")},Utils.prototype.getRandomId=function(prefix){return prefix+"-"+Math.random().toString(36).slice(-3)},Utils.prototype.startsWith=function(str,start){if("object"==typeof start){var result=!1;return start.forEach(function(s){0===str.indexOf(s)&&(result=!0)}),result}return 0===str.indexOf(start)},Utils.prototype.valueOrEmpty=function(value){return value?value:""},module.exports.Utils=new Utils}()},function(module,exports,__webpack_require__){!function(){function FileListPrinter(){}var printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils;FileListPrinter.prototype.generateFileList=function(diffFiles){var hideId=utils.getRandomId("d2h-hide"),showId=utils.getRandomId("d2h-show");return'
\n
Files changed ('+diffFiles.length+')  
\n +\n -\n
\n \n'+diffFiles.map(function(file){return' \n \n \n \n \n"}).join("\n")+"
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n  '+printerUtils.getDiffName(file)+"
\n"},module.exports.FileListPrinter=new FileListPrinter}()},function(module,exports,__webpack_require__){!function(){function PrinterUtils(){}function isDeletedName(name){return"dev/null"===name}function removeIns(line){return line.replace(/(]*>((.|\n)*?)<\/ins>)/g,"")}function removeDel(line){return line.replace(/(]*>((.|\n)*?)<\/del>)/g,"")}var jsDiff=__webpack_require__(5),utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;PrinterUtils.prototype.getHtmlId=function(file){var hashCode=function(text){var i,chr,len,hash=0;if(0===text.length)return hash;for(i=0,len=text.length;len>i;i++)chr=text.charCodeAt(i),hash=(hash<<5)-hash+chr,hash|=0;return hash};return"d2h-"+hashCode(this.getDiffName(file)).toString().slice(-6)},PrinterUtils.prototype.getDiffName=function(file){var oldFilename=file.oldName,newFilename=file.newName;return oldFilename&&newFilename&&oldFilename!==newFilename&&!isDeletedName(newFilename)?oldFilename+" -> "+newFilename:newFilename&&!isDeletedName(newFilename)?newFilename:oldFilename?oldFilename:"Unknown filename"},PrinterUtils.prototype.diffHighlight=function(diffLine1,diffLine2,config){var linePrefix1,linePrefix2,unprefixedLine1,unprefixedLine2,prefixSize=1;config.isCombined&&(prefixSize=2),linePrefix1=diffLine1.substr(0,prefixSize),linePrefix2=diffLine2.substr(0,prefixSize),unprefixedLine1=diffLine1.substr(prefixSize),unprefixedLine2=diffLine2.substr(prefixSize);var diff;diff=config.charByChar?jsDiff.diffChars(unprefixedLine1,unprefixedLine2):jsDiff.diffWordsWithSpace(unprefixedLine1,unprefixedLine2);var highlightedLine="",changedWords=[];if(!config.charByChar&&"words"===config.matching){var treshold=.25;"undefined"!=typeof config.matchWordsThreshold&&(treshold=config.matchWordsThreshold);var matcher=Rematch.rematch(function(a,b){var amod=a.value,bmod=b.value;return Rematch.distance(amod,bmod)}),removed=diff.filter(function(element){return element.removed}),added=diff.filter(function(element){return element.added}),chunks=matcher(added,removed);chunks.forEach(function(chunk){if(1===chunk[0].length&&1===chunk[1].length){var dist=Rematch.distance(chunk[0][0].value,chunk[1][0].value);treshold>dist&&(changedWords.push(chunk[0][0]),changedWords.push(chunk[1][0]))}})}return diff.forEach(function(part){var addClass=changedWords.indexOf(part)>-1?' class="d2h-change"':"",elemType=part.added?"ins":part.removed?"del":null,escapedValue=utils.escape(part.value);highlightedLine+=null!==elemType?"<"+elemType+addClass+">"+escapedValue+"":escapedValue}),{first:{prefix:linePrefix1,line:removeIns(highlightedLine)},second:{prefix:linePrefix2,line:removeDel(highlightedLine)}}},module.exports.PrinterUtils=new PrinterUtils}()},function(module,exports,__webpack_require__){"use strict";function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}exports.__esModule=!0;var _diffBase=__webpack_require__(6),_diffBase2=_interopRequireDefault(_diffBase),_diffCharacter=__webpack_require__(7),_diffWord=__webpack_require__(8),_diffLine=__webpack_require__(10),_diffSentence=__webpack_require__(11),_diffCss=__webpack_require__(12),_diffJson=__webpack_require__(13),_patchApply=__webpack_require__(14),_patchParse=__webpack_require__(15),_patchCreate=__webpack_require__(17),_convertDmp=__webpack_require__(18),_convertXml=__webpack_require__(19);exports.Diff=_diffBase2["default"],exports.diffChars=_diffCharacter.diffChars,exports.diffWords=_diffWord.diffWords,exports.diffWordsWithSpace=_diffWord.diffWordsWithSpace,exports.diffLines=_diffLine.diffLines,exports.diffTrimmedLines=_diffLine.diffTrimmedLines,exports.diffSentences=_diffSentence.diffSentences,exports.diffCss=_diffCss.diffCss,exports.diffJson=_diffJson.diffJson,exports.structuredPatch=_patchCreate.structuredPatch,exports.createTwoFilesPatch=_patchCreate.createTwoFilesPatch,exports.createPatch=_patchCreate.createPatch,exports.applyPatch=_patchApply.applyPatch,exports.applyPatches=_patchApply.applyPatches,exports.parsePatch=_patchParse.parsePatch,exports.convertChangesToDMP=_convertDmp.convertChangesToDMP,exports.convertChangesToXML=_convertXml.convertChangesToXML,exports.canonicalize=_diffJson.canonicalize},function(module,exports){"use strict";function Diff(){}function buildValues(diff,components,newString,oldString,useLongestToken){for(var componentPos=0,componentLen=components.length,newPos=0,oldPos=0;componentLen>componentPos;componentPos++){var component=components[componentPos];if(component.removed){if(component.value=oldString.slice(oldPos,oldPos+component.count).join(""),oldPos+=component.count,componentPos&&components[componentPos-1].added){var tmp=components[componentPos-1];components[componentPos-1]=components[componentPos],components[componentPos]=tmp}}else{if(!component.added&&useLongestToken){var value=newString.slice(newPos,newPos+component.count);value=value.map(function(value,i){var oldValue=oldString[oldPos+i];return oldValue.length>value.length?oldValue:value}),component.value=value.join("")}else component.value=newString.slice(newPos,newPos+component.count).join("");newPos+=component.count,component.added||(oldPos+=component.count)}}var lastComponent=components[componentLen-1];return(lastComponent.added||lastComponent.removed)&&diff.equals("",lastComponent.value)&&(components[componentLen-2].value+=lastComponent.value,components.pop()),components}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}exports.__esModule=!0,exports["default"]=Diff,Diff.prototype={diff:function(oldString,newString){function done(value){return callback?(setTimeout(function(){callback(void 0,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath=void 0,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1],_oldPos=(removePath?removePath.newPos:0)-diagonalPath;addPath&&(bestPath[diagonalPath-1]=void 0);var canAdd=addPath&&addPath.newPos+1=0&&oldLen>_oldPos;if(canAdd||canRemove){if(!canAdd||canRemove&&addPath.newPos=newLen&&_oldPos+1>=oldLen)return done(buildValues(self,basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=void 0}editLength++}var options=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],callback=options.callback;"function"==typeof options&&(callback=options,options={}),this.options=options;var self=this;oldString=this.castInput(oldString),newString=this.castInput(newString),oldString=this.removeEmpty(this.tokenize(oldString)),newString=this.removeEmpty(this.tokenize(newString));var newLen=newString.length,oldLen=oldString.length,editLength=1,maxEditLength=newLen+oldLen,bestPath=[{newPos:-1,components:[]}],oldPos=this.extractCommon(bestPath[0],newString,oldString,0);if(bestPath[0].newPos+1>=newLen&&oldPos+1>=oldLen)return done([{value:newString.join(""),count:newString.length}]);if(callback)!function exec(){setTimeout(function(){return editLength>maxEditLength?callback():void(execEditLength()||exec())},0)}();else for(;maxEditLength>=editLength;){var ret=execEditLength();if(ret)return ret}},pushComponent:function(components,added,removed){var last=components[components.length-1];last&&last.added===added&&last.removed===removed?components[components.length-1]={count:last.count+1,added:added,removed:removed}:components.push({count:1,added:added,removed:removed})},extractCommon:function(basePath,newString,oldString,diagonalPath){for(var newLen=newString.length,oldLen=oldString.length,newPos=basePath.newPos,oldPos=newPos-diagonalPath,commonCount=0;newLen>newPos+1&&oldLen>oldPos+1&&this.equals(newString[newPos+1],oldString[oldPos+1]);)newPos++,oldPos++,commonCount++;return commonCount&&basePath.components.push({count:commonCount}),basePath.newPos=newPos,oldPos},equals:function(left,right){return left===right},removeEmpty:function(array){for(var ret=[],i=0;ifuzzFactor))return!1;toPos++}}return!0}var options=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if("string"==typeof uniDiff&&(uniDiff=_parse.parsePatch(uniDiff)),Array.isArray(uniDiff)){if(uniDiff.length>1)throw new Error("applyPatch only works with a single input.");uniDiff=uniDiff[0]}for(var lines=source.split("\n"),hunks=uniDiff.hunks,compareLine=options.compareLine||function(lineNumber,line,operation,patchContent){return line===patchContent},errorCount=0,fuzzFactor=options.fuzzFactor||0,minLine=0,offset=0,removeEOFNL=void 0,addEOFNL=void 0,i=0;i=start+localOffset)return localOffset;forwardExhausted=!0}if(backwardExhausted);else{if(forwardExhausted||(wantForward=!0),start-localOffset>=minLine)return-localOffset++;backwardExhausted=!0,_again=!0}}}},module.exports=exports["default"]},function(module,exports,__webpack_require__){"use strict";function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i0?contextLines(prev.lines.slice(-options.context)):[],oldRangeStart-=curRange.length,newRangeStart-=curRange.length)}(_curRange=curRange).push.apply(_curRange,_toConsumableArray(lines.map(function(entry){return(current.added?"+":"-")+entry}))),current.added?newLine+=lines.length:oldLine+=lines.length}else{if(oldRangeStart)if(lines.length<=2*options.context&&i=diff.length-2&&lines.length<=options.context){var oldEOFNewline=/\n$/.test(oldStr),newEOFNewline=/\n$/.test(newStr);0!=lines.length||oldEOFNewline?oldEOFNewline&&newEOFNewline||curRange.push("\\ No newline at end of file"):curRange.splice(hunk.oldLines,0,"\\ No newline at end of file")}hunks.push(hunk),oldRangeStart=0,newRangeStart=0,curRange=[]}oldLine+=lines.length,newLine+=lines.length}},i=0;i"):change.removed&&ret.push(""),ret.push(escapeHTML(change.value)),change.added?ret.push(""):change.removed&&ret.push(""); -}return ret.join("")}function escapeHTML(s){var n=s;return n=n.replace(/&/g,"&"),n=n.replace(//g,">"),n=n.replace(/"/g,""")}exports.__esModule=!0,exports.convertChangesToXML=convertChangesToXML},function(module){!function(){function levenshtein(a,b){if(0==a.length)return b.length;if(0==b.length)return a.length;var i,matrix=[];for(i=0;i<=b.length;i++)matrix[i]=[i];var j;for(j=0;j<=a.length;j++)matrix[0][j]=j;for(i=1;i<=b.length;i++)for(j=1;j<=a.length;j++)matrix[i][j]=b.charAt(i-1)==a.charAt(j-1)?matrix[i-1][j-1]:Math.min(matrix[i-1][j-1]+1,Math.min(matrix[i][j-1]+1,matrix[i-1][j]+1));return matrix[b.length][a.length]}var Rematch={};Rematch.arrayToString=function arrayToString(a){return"[object Array]"===Object.prototype.toString.apply(a,[])?"["+a.map(arrayToString).join(", ")+"]":a},Rematch.levenshtein=levenshtein,Rematch.distance=function(x,y){x=x.trim(),y=y.trim();var lev=levenshtein(x,y),score=lev/(x.length+y.length);return score},Rematch.rematch=function(distanceFunction){function findBestMatch(a,b,cache){var cachecount=0;for(var key in cache)cachecount++;for(var bestMatch,bestMatchDist=1/0,i=0;imd&&(bestMatchDist=md,bestMatch={indexA:i,indexB:j,score:bestMatchDist})}return bestMatch}function group(a,b,level,cache){"undefined"==typeof cache&&(cache={});var bm=(Math.min(a.length,b.length),findBestMatch(a,b,cache));if(level||(level=0),!bm||a.length+b.length<3)return[[a,b]];var a1=a.slice(0,bm.indexA),b1=b.slice(0,bm.indexB),aMatch=[a[bm.indexA]],bMatch=[b[bm.indexB]],tailA=bm.indexA+1,tailB=bm.indexB+1,a2=a.slice(tailA),b2=b.slice(tailB),group1=group(a1,b1,level+1,cache),groupMatch=group(aMatch,bMatch,level+1,cache),group2=group(a2,b2,level+1,cache),result=groupMatch;return(bm.indexA>0||bm.indexB>0)&&(result=group1.concat(result)),(a.length>tailA||b.length>tailB)&&(result=result.concat(group2)),result}return group},module.exports.Rematch=Rematch}(this)},function(module,exports,__webpack_require__){!function(){function HtmlPrinter(){}var lineByLinePrinter=__webpack_require__(22).LineByLinePrinter,sideBySidePrinter=__webpack_require__(23).SideBySidePrinter;HtmlPrinter.prototype.generateLineByLineJsonHtml=lineByLinePrinter.generateLineByLineJsonHtml,HtmlPrinter.prototype.generateSideBySideJsonHtml=sideBySidePrinter.generateSideBySideJsonHtml,module.exports.HtmlPrinter=new HtmlPrinter}(this)},function(module,exports,__webpack_require__){!function(){function LineByLinePrinter(){}function generateFileHtml(file,config){return file.blocks.map(function(block){function processChangeBlock(){var matches,insertType,deleteType,doMatching="lines"===config.matching||"words"===config.matching;doMatching?(matches=matcher(oldLines,newLines),insertType=diffParser.LINE_TYPE.INSERT_CHANGES,deleteType=diffParser.LINE_TYPE.DELETE_CHANGES):(matches=[[oldLines,newLines]],insertType=diffParser.LINE_TYPE.INSERTS,deleteType=diffParser.LINE_TYPE.DELETES),matches.forEach(function(match){{var oldLine,newLine,oldLines=match[0],newLines=match[1],processedOldLines=[],processedNewLines=[],j=0,common=Math.min(oldLines.length,newLines.length);Math.max(oldLines.length,newLines.length)}for(j=0;common>j;j++){oldLine=oldLines[j],newLine=newLines[j],config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,config);processedOldLines+=generateLineHtml(deleteType,oldLine.oldNumber,oldLine.newNumber,diff.first.line,diff.first.prefix),processedNewLines+=generateLineHtml(insertType,newLine.oldNumber,newLine.newNumber,diff.second.line,diff.second.prefix)}lines+=processedOldLines+processedNewLines,lines+=processLines(oldLines.slice(common),newLines.slice(common)),processedOldLines=[],processedNewLines=[]}),oldLines=[],newLines=[]}for(var lines='\n \n
'+utils.escape(block.header)+"
\n\n",oldLines=[],newLines=[],i=0;i0||line.type!==diffParser.LINE_TYPE.DELETES&&oldLines.length>0)&&processChangeBlock(),line.type==diffParser.LINE_TYPE.CONTEXT?lines+=generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine):line.type!=diffParser.LINE_TYPE.INSERTS||oldLines.length?line.type==diffParser.LINE_TYPE.DELETES?oldLines.push(line):line.type==diffParser.LINE_TYPE.INSERTS&&oldLines.length?newLines.push(line):(console.error("unknown state in html line-by-line generator"),processChangeBlock()):lines+=generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine)}return processChangeBlock(),lines}).join("\n")}function processLines(oldLines,newLines){var lines="";for(j=0;j");var htmlContent="";return content&&(htmlContent=''+content+""),'\n
'+utils.valueOrEmpty(oldNumber)+'
'+utils.valueOrEmpty(newNumber)+'
\n
'+htmlPrefix+htmlContent+"
\n\n"}function generateEmptyDiff(){return'\n
File without changes
\n\n'}var diffParser=__webpack_require__(1).DiffParser,printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;LineByLinePrinter.prototype.generateLineByLineJsonHtml=function(diffFiles,config){return'
\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?generateFileHtml(file,config):generateEmptyDiff(),'
\n
\n
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n \n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n \n \n '+diffs+" \n
\n
\n
\n
\n"}).join("\n")+"
\n"};var matcher=Rematch.rematch(function(a,b){var amod=a.content.substr(1),bmod=b.content.substr(1);return Rematch.distance(amod,bmod)});module.exports.LineByLinePrinter=new LineByLinePrinter}(this)},function(module,exports,__webpack_require__){!function(){function SideBySidePrinter(){}function generateSideBySideFileHtml(file,config){var fileHtml={};return fileHtml.left="",fileHtml.right="",file.blocks.forEach(function(block){function processChangeBlock(){var matches,insertType,deleteType,doMatching="lines"===config.matching||"words"===config.matching;doMatching?(matches=matcher(oldLines,newLines),insertType=diffParser.LINE_TYPE.INSERT_CHANGES,deleteType=diffParser.LINE_TYPE.DELETE_CHANGES):(matches=[[oldLines,newLines]],insertType=diffParser.LINE_TYPE.INSERTS,deleteType=diffParser.LINE_TYPE.DELETES),matches.forEach(function(match){var tmpHtml,oldLine,newLine,oldLines=match[0],newLines=match[1],j=0,common=Math.min(oldLines.length,newLines.length),max=Math.max(oldLines.length,newLines.length);for(j=0;common>j;j++){oldLine=oldLines[j],newLine=newLines[j],config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,config);fileHtml.left+=generateSingleLineHtml(deleteType,oldLine.oldNumber,diff.first.line,diff.first.prefix),fileHtml.right+=generateSingleLineHtml(insertType,newLine.newNumber,diff.second.line,diff.second.prefix)}if(max>common){{oldLines.slice(common),newLines.slice(common)}tmpHtml=processLines(oldLines.slice(common),newLines.slice(common)),fileHtml.left+=tmpHtml.left,fileHtml.right+=tmpHtml.right}}),oldLines=[],newLines=[]}fileHtml.left+='\n \n
'+utils.escape(block.header)+"
\n\n",fileHtml.right+='\n \n
\n\n';for(var oldLines=[],newLines=[],i=0;i0||line.type!==diffParser.LINE_TYPE.DELETES&&oldLines.length>0)&&processChangeBlock(),line.type==diffParser.LINE_TYPE.CONTEXT?(fileHtml.left+=generateSingleLineHtml(line.type,line.oldNumber,escapedLine,prefix),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix)):line.type!=diffParser.LINE_TYPE.INSERTS||oldLines.length?line.type==diffParser.LINE_TYPE.DELETES?oldLines.push(line):line.type==diffParser.LINE_TYPE.INSERTS&&oldLines.length?newLines.push(line):(console.error("unknown state in html side-by-side generator"),processChangeBlock()):(fileHtml.left+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix))}processChangeBlock()}),fileHtml}function processLines(oldLines,newLines){var fileHtml={};fileHtml.left="",fileHtml.right="";var maxLinesNumber=Math.max(oldLines.length,newLines.length);for(j=0;j");var htmlContent="";return content&&(htmlContent=''+content+""),'\n '+number+'\n
'+htmlPrefix+htmlContent+"
\n \n"}function generateEmptyDiff(){var fileHtml={};return fileHtml.right="",fileHtml.left='\n
File without changes
\n\n',fileHtml}var diffParser=__webpack_require__(1).DiffParser,printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;SideBySidePrinter.prototype.generateSideBySideJsonHtml=function(diffFiles,config){return'
\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?generateSideBySideFileHtml(file,config):generateEmptyDiff(),'
\n
\n
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n \n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n
\n \n \n '+diffs.left+' \n
\n
\n
\n
\n
\n \n \n '+diffs.right+" \n
\n
\n
\n
\n
\n"}).join("\n")+"
\n"};var matcher=Rematch.rematch(function(a,b){var amod=a.content.substr(1),bmod=b.content.substr(1);return Rematch.distance(amod,bmod)});module.exports.SideBySidePrinter=new SideBySidePrinter}(this)}]); \ No newline at end of file +}return ret.join("")}function escapeHTML(s){var n=s;return n=n.replace(/&/g,"&"),n=n.replace(//g,">"),n=n.replace(/"/g,""")}exports.__esModule=!0,exports.convertChangesToXML=convertChangesToXML},function(module){!function(){function levenshtein(a,b){if(0==a.length)return b.length;if(0==b.length)return a.length;var i,matrix=[];for(i=0;i<=b.length;i++)matrix[i]=[i];var j;for(j=0;j<=a.length;j++)matrix[0][j]=j;for(i=1;i<=b.length;i++)for(j=1;j<=a.length;j++)matrix[i][j]=b.charAt(i-1)==a.charAt(j-1)?matrix[i-1][j-1]:Math.min(matrix[i-1][j-1]+1,Math.min(matrix[i][j-1]+1,matrix[i-1][j]+1));return matrix[b.length][a.length]}var Rematch={};Rematch.arrayToString=function arrayToString(a){return"[object Array]"===Object.prototype.toString.apply(a,[])?"["+a.map(arrayToString).join(", ")+"]":a},Rematch.levenshtein=levenshtein,Rematch.distance=function(x,y){x=x.trim(),y=y.trim();var lev=levenshtein(x,y),score=lev/(x.length+y.length);return score},Rematch.rematch=function(distanceFunction){function findBestMatch(a,b,cache){var cachecount=0;for(var key in cache)cachecount++;for(var bestMatch,bestMatchDist=1/0,i=0;imd&&(bestMatchDist=md,bestMatch={indexA:i,indexB:j,score:bestMatchDist})}return bestMatch}function group(a,b,level,cache){"undefined"==typeof cache&&(cache={});var bm=findBestMatch(a,b,cache);if(level||(level=0),!bm||a.length+b.length<3)return[[a,b]];var a1=a.slice(0,bm.indexA),b1=b.slice(0,bm.indexB),aMatch=[a[bm.indexA]],bMatch=[b[bm.indexB]],tailA=bm.indexA+1,tailB=bm.indexB+1,a2=a.slice(tailA),b2=b.slice(tailB),group1=group(a1,b1,level+1,cache),groupMatch=group(aMatch,bMatch,level+1,cache),group2=group(a2,b2,level+1,cache),result=groupMatch;return(bm.indexA>0||bm.indexB>0)&&(result=group1.concat(result)),(a.length>tailA||b.length>tailB)&&(result=result.concat(group2)),result}return group},module.exports.Rematch=Rematch}()},function(module,exports,__webpack_require__){!function(){function HtmlPrinter(){}var LineByLinePrinter=__webpack_require__(22).LineByLinePrinter,sideBySidePrinter=__webpack_require__(23).SideBySidePrinter;HtmlPrinter.prototype.generateLineByLineJsonHtml=function(diffFiles,config){var lineByLinePrinter=new LineByLinePrinter(config);return lineByLinePrinter.generateLineByLineJsonHtml(diffFiles)},HtmlPrinter.prototype.generateSideBySideJsonHtml=sideBySidePrinter.generateSideBySideJsonHtml,module.exports.HtmlPrinter=new HtmlPrinter}()},function(module,exports,__webpack_require__){!function(){function LineByLinePrinter(config){this.config=config}var diffParser=__webpack_require__(1).DiffParser,printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;LineByLinePrinter.prototype.generateLineByLineJsonHtml=function(diffFiles){var that=this;return'
\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?that._generateFileHtml(file):that._generateEmptyDiff(),'
\n
\n
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n \n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n \n \n '+diffs+" \n
\n
\n
\n
\n"}).join("\n")+"
\n"};var matcher=Rematch.rematch(function(a,b){var amod=a.content.substr(1),bmod=b.content.substr(1);return Rematch.distance(amod,bmod)});LineByLinePrinter.prototype._generateFileHtml=function(file){var that=this;return file.blocks.map(function(block){function processChangeBlock(){var matches,insertType,deleteType,doMatching="lines"===that.config.matching||"words"===that.config.matching;doMatching?(matches=matcher(oldLines,newLines),insertType=diffParser.LINE_TYPE.INSERT_CHANGES,deleteType=diffParser.LINE_TYPE.DELETE_CHANGES):(matches=[[oldLines,newLines]],insertType=diffParser.LINE_TYPE.INSERTS,deleteType=diffParser.LINE_TYPE.DELETES),matches.forEach(function(match){oldLines=match[0],newLines=match[1];for(var oldLine,newLine,processedOldLines=[],processedNewLines=[],common=Math.min(oldLines.length,newLines.length),j=0;common>j;j++){oldLine=oldLines[j],newLine=newLines[j],that.config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,that.config);processedOldLines+=that._generateLineHtml(deleteType,oldLine.oldNumber,oldLine.newNumber,diff.first.line,diff.first.prefix),processedNewLines+=that._generateLineHtml(insertType,newLine.oldNumber,newLine.newNumber,diff.second.line,diff.second.prefix)}lines+=processedOldLines+processedNewLines,lines+=that._processLines(oldLines.slice(common),newLines.slice(common))}),oldLines=[],newLines=[]}for(var lines='\n \n
'+utils.escape(block.header)+"
\n\n",oldLines=[],newLines=[],i=0;i0||line.type!==diffParser.LINE_TYPE.DELETES&&oldLines.length>0)&&processChangeBlock(),line.type===diffParser.LINE_TYPE.CONTEXT?lines+=that._generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine):line.type!==diffParser.LINE_TYPE.INSERTS||oldLines.length?line.type===diffParser.LINE_TYPE.DELETES?oldLines.push(line):line.type===diffParser.LINE_TYPE.INSERTS&&Boolean(oldLines.length)?newLines.push(line):(console.error("Unknown state in html line-by-line generator"),processChangeBlock()):lines+=that._generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine)}return processChangeBlock(),lines}).join("\n")},LineByLinePrinter.prototype._processLines=function(oldLines,newLines){for(var lines="",i=0;i");var htmlContent="";return content&&(htmlContent=''+content+""),'\n
'+utils.valueOrEmpty(oldNumber)+'
'+utils.valueOrEmpty(newNumber)+'
\n
'+htmlPrefix+htmlContent+"
\n\n"},LineByLinePrinter.prototype._generateEmptyDiff=function(){return'\n
File without changes
\n\n'},module.exports.LineByLinePrinter=LineByLinePrinter}()},function(module,exports,__webpack_require__){!function(){function SideBySidePrinter(){}function generateSideBySideFileHtml(file,config){var fileHtml={};return fileHtml.left="",fileHtml.right="",file.blocks.forEach(function(block){function processChangeBlock(){var matches,insertType,deleteType,doMatching="lines"===config.matching||"words"===config.matching;doMatching?(matches=matcher(oldLines,newLines),insertType=diffParser.LINE_TYPE.INSERT_CHANGES,deleteType=diffParser.LINE_TYPE.DELETE_CHANGES):(matches=[[oldLines,newLines]],insertType=diffParser.LINE_TYPE.INSERTS,deleteType=diffParser.LINE_TYPE.DELETES),matches.forEach(function(match){oldLines=match[0],newLines=match[1];for(var common=Math.min(oldLines.length,newLines.length),max=Math.max(oldLines.length,newLines.length),j=0;common>j;j++){var oldLine=oldLines[j],newLine=newLines[j];config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,config);fileHtml.left+=generateSingleLineHtml(deleteType,oldLine.oldNumber,diff.first.line,diff.first.prefix),fileHtml.right+=generateSingleLineHtml(insertType,newLine.newNumber,diff.second.line,diff.second.prefix)}if(max>common){var oldSlice=oldLines.slice(common),newSlice=newLines.slice(common),tmpHtml=processLines(oldSlice,newSlice);fileHtml.left+=tmpHtml.left,fileHtml.right+=tmpHtml.right}}),oldLines=[],newLines=[]}fileHtml.left+='\n \n
'+utils.escape(block.header)+"
\n\n",fileHtml.right+='\n \n
\n\n';for(var oldLines=[],newLines=[],i=0;i0||line.type!==diffParser.LINE_TYPE.DELETES&&oldLines.length>0)&&processChangeBlock(),line.type===diffParser.LINE_TYPE.CONTEXT?(fileHtml.left+=generateSingleLineHtml(line.type,line.oldNumber,escapedLine,prefix),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix)):line.type!==diffParser.LINE_TYPE.INSERTS||oldLines.length?line.type===diffParser.LINE_TYPE.DELETES?oldLines.push(line):line.type===diffParser.LINE_TYPE.INSERTS&&Boolean(oldLines.length)?newLines.push(line):(console.error("unknown state in html side-by-side generator"),processChangeBlock()):(fileHtml.left+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine,prefix))}processChangeBlock()}),fileHtml}function processLines(oldLines,newLines){var fileHtml={};fileHtml.left="",fileHtml.right="";for(var maxLinesNumber=Math.max(oldLines.length,newLines.length),i=0;maxLinesNumber>i;i++){var oldContent,newContent,oldPrefix,newPrefix,oldLine=oldLines[i],newLine=newLines[i];oldLine&&(oldContent=utils.escape(oldLine.content.substr(1)),oldPrefix=oldLine.content[0]),newLine&&(newContent=utils.escape(newLine.content.substr(1)),newPrefix=newLine.content[0]),oldLine&&newLine?(fileHtml.left+=generateSingleLineHtml(oldLine.type,oldLine.oldNumber,oldContent,oldPrefix),fileHtml.right+=generateSingleLineHtml(newLine.type,newLine.newNumber,newContent,newPrefix)):oldLine?(fileHtml.left+=generateSingleLineHtml(oldLine.type,oldLine.oldNumber,oldContent,oldPrefix),fileHtml.right+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","","")):newLine?(fileHtml.left+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=generateSingleLineHtml(newLine.type,newLine.newNumber,newContent,newPrefix)):console.error("How did it get here?")}return fileHtml}function generateSingleLineHtml(type,number,content,prefix){var htmlPrefix="";prefix&&(htmlPrefix=''+prefix+"");var htmlContent="";return content&&(htmlContent=''+content+""),'\n '+number+'\n
'+htmlPrefix+htmlContent+"
\n \n"}function generateEmptyDiff(){var fileHtml={};return fileHtml.right="",fileHtml.left='\n
File without changes
\n\n',fileHtml}var diffParser=__webpack_require__(1).DiffParser,printerUtils=__webpack_require__(4).PrinterUtils,utils=__webpack_require__(2).Utils,Rematch=__webpack_require__(20).Rematch;SideBySidePrinter.prototype.generateSideBySideJsonHtml=function(diffFiles,config){return'
\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?generateSideBySideFileHtml(file,config):generateEmptyDiff(),'
\n
\n
\n +'+file.addedLines+'\n \n -'+file.deletedLines+'\n \n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n
\n \n \n '+diffs.left+' \n
\n
\n
\n
\n
\n \n \n '+diffs.right+" \n
\n
\n
\n
\n
\n"}).join("\n")+"
\n"};var matcher=Rematch.rematch(function(a,b){var amod=a.content.substr(1),bmod=b.content.substr(1);return Rematch.distance(amod,bmod)});module.exports.SideBySidePrinter=new SideBySidePrinter}()}]); \ No newline at end of file diff --git a/src/diff-parser.js b/src/diff-parser.js index 4d78a519..db347112 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var utils = require('./utils.js').Utils; @@ -31,6 +31,7 @@ var newLine = null; var saveBlock = function() { + /* Add previous block(if exists) before start a new file */ if (currentBlock) { currentFile.blocks.push(currentBlock); @@ -39,6 +40,7 @@ }; var saveFile = function() { + /* * Add previous file(if exists) before start a new one * if it has name (to avoid binary files errors) @@ -216,11 +218,11 @@ var nameSplit = filename.split('.'); if (nameSplit.length > 1) { return nameSplit[nameSplit.length - 1]; - } else { - return language; } + + return language; } - module.exports['DiffParser'] = new DiffParser(); + module.exports.DiffParser = new DiffParser(); -})(this); +})(); diff --git a/src/diff2html.js b/src/diff2html.js index 7914f0f2..49a535c9 100644 --- a/src/diff2html.js +++ b/src/diff2html.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var diffParser = require('./diff-parser.js').DiffParser; var fileLister = require('./file-list-printer.js').FileListPrinter; @@ -17,9 +17,9 @@ /* * Line diff type configuration var config = { - "wordByWord": true, // (default) + 'wordByWord': true, // (default) // OR - "charByChar": true + 'charByChar': true }; */ @@ -37,23 +37,23 @@ var configOrEmpty = config || {}; var diffJson = diffInput; - if(!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') { + if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') { diffJson = diffParser.generateDiffJson(diffInput); } - var fileList = ""; - if(configOrEmpty.showFiles === true) { + var fileList = ''; + if (configOrEmpty.showFiles === true) { fileList = fileLister.generateFileList(diffJson, configOrEmpty); } - var diffOutput = ""; - if(configOrEmpty.outputFormat === 'side-by-side') { + var diffOutput = ''; + if (configOrEmpty.outputFormat === 'side-by-side') { diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); } else { diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); } - return fileList + diffOutput + return fileList + diffOutput; }; @@ -66,9 +66,9 @@ */ Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'diff'; - configOrEmpty['outputFormat'] = 'line-by-line'; - return this.getPrettyHtml(diffInput, configOrEmpty) + configOrEmpty.inputFormat = 'diff'; + configOrEmpty.outputFormat = 'line-by-line'; + return this.getPrettyHtml(diffInput, configOrEmpty); }; /* @@ -76,9 +76,9 @@ */ Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'json'; - configOrEmpty['outputFormat'] = 'line-by-line'; - return this.getPrettyHtml(diffJson, configOrEmpty) + configOrEmpty.inputFormat = 'json'; + configOrEmpty.outputFormat = 'line-by-line'; + return this.getPrettyHtml(diffJson, configOrEmpty); }; /* @@ -86,9 +86,9 @@ */ Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'diff'; - configOrEmpty['outputFormat'] = 'side-by-side'; - return this.getPrettyHtml(diffInput, configOrEmpty) + configOrEmpty.inputFormat = 'diff'; + configOrEmpty.outputFormat = 'side-by-side'; + return this.getPrettyHtml(diffInput, configOrEmpty); }; /* @@ -96,15 +96,15 @@ */ Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; - configOrEmpty['inputFormat'] = 'json'; - configOrEmpty['outputFormat'] = 'side-by-side'; - return this.getPrettyHtml(diffJson, configOrEmpty) + configOrEmpty.inputFormat = 'json'; + configOrEmpty.outputFormat = 'side-by-side'; + return this.getPrettyHtml(diffJson, configOrEmpty); }; - var diffName = 'Diff2Html'; var diffObject = new Diff2Html(); - module.exports[diffName] = diffObject; + module.exports.Diff2Html = diffObject; + // Expose diff2html in the browser - global[diffName] = diffObject; + global.Diff2Html = diffObject; -})(this); +})(); diff --git a/src/file-list-printer.js b/src/file-list-printer.js index 8cb2f765..493e1b00 100644 --- a/src/file-list-printer.js +++ b/src/file-list-printer.js @@ -5,39 +5,39 @@ * */ -(function (ctx, undefined) { - - var printerUtils = require('./printer-utils.js').PrinterUtils; - var utils = require('./utils.js').Utils; - - function FileListPrinter() { - } - - FileListPrinter.prototype.generateFileList = function (diffFiles) { - var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page - var showId = utils.getRandomId("d2h-show"); - return '
\n' + - '
Files changed (' + diffFiles.length + ')  
\n' + - ' +\n' + - ' -\n' + - '
\n' + - ' \n' + - - - diffFiles.map(function (file) { - return ' \n' + - ' \n' + - ' \n' + - ' \n' + - ' \n' - }).join('\n') + - '
\n' + - ' +' + file.addedLines + '\n' + - ' \n' + - ' -' + file.deletedLines + '\n' + - '  ' + printerUtils.getDiffName(file) + '
\n'; - }; - - module.exports['FileListPrinter'] = new FileListPrinter(); - -})(this); +(function() { + + var printerUtils = require('./printer-utils.js').PrinterUtils; + var utils = require('./utils.js').Utils; + + function FileListPrinter() { + } + + FileListPrinter.prototype.generateFileList = function(diffFiles) { + var hideId = utils.getRandomId('d2h-hide'); //necessary if there are 2 elements like this in the same page + var showId = utils.getRandomId('d2h-show'); + return '
\n' + + '
Files changed (' + diffFiles.length + ')  
\n' + + ' +\n' + + ' -\n' + + '
\n' + + ' \n' + + + + diffFiles.map(function(file) { + return ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n'; + }).join('\n') + + '
\n' + + ' +' + file.addedLines + '\n' + + ' \n' + + ' -' + file.deletedLines + '\n' + + '  ' + printerUtils.getDiffName(file) + '
\n'; + }; + + module.exports.FileListPrinter = new FileListPrinter(); + +})(); diff --git a/src/html-printer.js b/src/html-printer.js index 3690b44c..e5d6b2d3 100644 --- a/src/html-printer.js +++ b/src/html-printer.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter; var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter; @@ -20,6 +20,6 @@ HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml; - module.exports['HtmlPrinter'] = new HtmlPrinter(); + module.exports.HtmlPrinter = new HtmlPrinter(); -})(this); +})(); diff --git a/src/line-by-line-printer.js b/src/line-by-line-printer.js index 2f72f06e..1f248d9a 100644 --- a/src/line-by-line-printer.js +++ b/src/line-by-line-printer.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var diffParser = require('./diff-parser.js').DiffParser; var printerUtils = require('./printer-utils.js').PrinterUtils; @@ -23,9 +23,9 @@ var diffs; if (file.blocks.length) { - diffs = that.generateFileHtml(file); + diffs = that._generateFileHtml(file); } else { - diffs = that.generateEmptyDiff(); + diffs = that._generateEmptyDiff(); } return '
\n' + @@ -54,13 +54,14 @@ '
\n'; }; - var matcher=Rematch.rematch(function(a,b) { - var amod = a.content.substr(1), - bmod = b.content.substr(1); + var matcher = Rematch.rematch(function(a, b) { + var amod = a.content.substr(1); + var bmod = b.content.substr(1); + return Rematch.distance(amod, bmod); }); - LineByLinePrinter.prototype.generateFileHtml = function(file) { + LineByLinePrinter.prototype._generateFileHtml = function(file) { var that = this; return file.blocks.map(function(block) { @@ -73,50 +74,53 @@ var oldLines = []; var newLines = []; + function processChangeBlock() { var matches; var insertType; var deleteType; - var doMatching = that.config.matching === "lines" || that.config.matching === "words"; + + var doMatching = that.config.matching === 'lines' || that.config.matching === 'words'; + if (doMatching) { matches = matcher(oldLines, newLines); insertType = diffParser.LINE_TYPE.INSERT_CHANGES; deleteType = diffParser.LINE_TYPE.DELETE_CHANGES; } else { - matches = [[oldLines,newLines]]; + matches = [[oldLines, newLines]]; insertType = diffParser.LINE_TYPE.INSERTS; deleteType = diffParser.LINE_TYPE.DELETES; } - matches.forEach(function(match){ - var oldLines = match[0]; - var newLines = match[1]; + + matches.forEach(function(match) { + oldLines = match[0]; + newLines = match[1]; + var processedOldLines = []; var processedNewLines = []; - var j = 0; - var oldLine, newLine, - common = Math.min(oldLines.length, newLines.length), - max = Math.max(oldLines.length, newLines.length); - for (j = 0; j < common; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; - - that.config.isCombined = file.isCombined; - var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config); - - processedOldLines += - that.generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber, - diff.first.line, diff.first.prefix); - processedNewLines += - that.generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber, - diff.second.line, diff.second.prefix); - } - - lines += processedOldLines + processedNewLines; - lines += that.processLines(oldLines.slice(common), newLines.slice(common)); - - processedOldLines = []; - processedNewLines = []; + + var common = Math.min(oldLines.length, newLines.length); + + var oldLine, newLine; + for (var j = 0; j < common; j++) { + oldLine = oldLines[j]; + newLine = newLines[j]; + + that.config.isCombined = file.isCombined; + var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config); + + processedOldLines += + that._generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber, + diff.first.line, diff.first.prefix); + processedNewLines += + that._generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber, + diff.second.line, diff.second.prefix); + } + + lines += processedOldLines + processedNewLines; + lines += that._processLines(oldLines.slice(common), newLines.slice(common)); }); + oldLines = []; newLines = []; } @@ -125,20 +129,21 @@ var line = block.lines[i]; var escapedLine = utils.escape(line.content); - if ( line.type !== diffParser.LINE_TYPE.INSERTS && - (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { + if (line.type !== diffParser.LINE_TYPE.INSERTS && + (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { processChangeBlock(); } - if (line.type == diffParser.LINE_TYPE.CONTEXT) { - lines += that.generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length) { - lines += that.generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.DELETES) { + + if (line.type === diffParser.LINE_TYPE.CONTEXT) { + lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) { + lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type === diffParser.LINE_TYPE.DELETES) { 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); } else { - console.error('unknown state in html line-by-line generator'); + console.error('Unknown state in html line-by-line generator'); processChangeBlock(); } } @@ -147,27 +152,27 @@ return lines; }).join('\n'); - } + }; - LineByLinePrinter.prototype.processLines = function(oldLines, newLines) { + LineByLinePrinter.prototype._processLines = function(oldLines, newLines) { var lines = ''; - for (j = 0; j < oldLines.length; j++) { - var oldLine = oldLines[j]; + for (var i = 0; i < oldLines.length; i++) { + var oldLine = oldLines[i]; 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 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; - } + }; - LineByLinePrinter.prototype.generateLineHtml = function(type, oldNumber, newNumber, content, prefix) { + LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) { var htmlPrefix = ''; if (prefix) { htmlPrefix = '' + prefix + ''; @@ -187,9 +192,9 @@ '
' + htmlPrefix + htmlContent + '
' + ' \n' + '\n'; - } + }; - LineByLinePrinter.prototype.generateEmptyDiff = function() { + LineByLinePrinter.prototype._generateEmptyDiff = function() { return '\n' + ' ' + '
' + @@ -197,8 +202,8 @@ '
' + ' \n' + '\n'; - } + }; - module.exports['LineByLinePrinter'] = LineByLinePrinter; + module.exports.LineByLinePrinter = LineByLinePrinter; -})(this); +})(); diff --git a/src/printer-utils.js b/src/printer-utils.js index 6e69c074..f7fd1ef5 100644 --- a/src/printer-utils.js +++ b/src/printer-utils.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var jsDiff = require('diff'); var utils = require('./utils.js').Utils; @@ -15,39 +15,41 @@ } PrinterUtils.prototype.getHtmlId = function(file) { - var hashCode = function(text) { - var hash = 0, i, chr, len; - if (text.length == 0) return hash; + var hashCode = function(text) { + var i, chr, len; + var hash = 0; + + if (text.length === 0) return hash; + for (i = 0, len = text.length; i < len; i++) { - chr = text.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; + chr = text.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } + 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) { var oldFilename = file.oldName; var newFilename = file.newName; - if (oldFilename && newFilename - && oldFilename !== newFilename - && !isDeletedName(newFilename)) { + if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) { return oldFilename + ' -> ' + newFilename; } else if (newFilename && !isDeletedName(newFilename)) { return newFilename; } else if (oldFilename) { return oldFilename; - } else { - return 'Unknown filename'; } + + return 'Unknown filename'; }; PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) { - var lineStart1, lineStart2; + var linePrefix1, linePrefix2, unprefixedLine1, unprefixedLine2; var prefixSize = 1; @@ -55,17 +57,16 @@ prefixSize = 2; } - lineStart1 = diffLine1.substr(0, prefixSize); - lineStart2 = diffLine2.substr(0, prefixSize); - - diffLine1 = diffLine1.substr(prefixSize); - diffLine2 = diffLine2.substr(prefixSize); + linePrefix1 = diffLine1.substr(0, prefixSize); + linePrefix2 = diffLine2.substr(0, prefixSize); + unprefixedLine1 = diffLine1.substr(prefixSize); + unprefixedLine2 = diffLine2.substr(prefixSize); var diff; if (config.charByChar) { - diff = jsDiff.diffChars(diffLine1, diffLine2); + diff = jsDiff.diffChars(unprefixedLine1, unprefixedLine2); } else { - diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); + diff = jsDiff.diffWordsWithSpace(unprefixedLine1, unprefixedLine2); } var highlightedLine = ''; @@ -73,25 +74,30 @@ var changedWords = []; if (!config.charByChar && config.matching === 'words') { var treshold = 0.25; - if (typeof(config.matchWordsThreshold) !== "undefined") { + + if (typeof(config.matchWordsThreshold) !== 'undefined') { treshold = config.matchWordsThreshold; } + var matcher = Rematch.rematch(function(a, b) { - var amod = a.value, - bmod = b.value, - result = Rematch.distance(amod, bmod); - return result; + var amod = a.value; + var bmod = b.value; + + return Rematch.distance(amod, bmod); }); - var removed = diff.filter(function isRemoved(element){ + + var removed = diff.filter(function isRemoved(element) { return element.removed; }); - var added = diff.filter(function isAdded(element){ + + var added = diff.filter(function isAdded(element) { return element.added; }); + var chunks = matcher(added, removed); - chunks = chunks.forEach(function(chunk){ - if(chunk[0].length === 1 && chunk[1].length === 1) { - var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value) + chunks.forEach(function(chunk) { + if (chunk[0].length === 1 && chunk[1].length === 1) { + var dist = Rematch.distance(chunk[0][0].value, chunk[1][0].value); if (dist < treshold) { changedWords.push(chunk[0][0]); changedWords.push(chunk[1][0]); @@ -99,6 +105,7 @@ } }); } + diff.forEach(function(part) { var addClass = changedWords.indexOf(part) > -1 ? ' class="d2h-change"' : ''; var elemType = part.added ? 'ins' : part.removed ? 'del' : null; @@ -113,11 +120,11 @@ return { first: { - prefix: lineStart1, + prefix: linePrefix1, line: removeIns(highlightedLine) }, second: { - prefix: lineStart2, + prefix: linePrefix2, line: removeDel(highlightedLine) } } @@ -135,6 +142,6 @@ return line.replace(/(]*>((.|\n)*?)<\/del>)/g, ''); } - module.exports['PrinterUtils'] = new PrinterUtils(); + module.exports.PrinterUtils = new PrinterUtils(); -})(this); +})(); diff --git a/src/rematch.js b/src/rematch.js index 1cbe50a7..912cfc70 100644 --- a/src/rematch.js +++ b/src/rematch.js @@ -6,72 +6,76 @@ * */ -(function(ctx, undefined) { +(function() { + var Rematch = {}; Rematch.arrayToString = function arrayToString(a) { - if (Object.prototype.toString.apply(a,[]) === "[object Array]") { + if (Object.prototype.toString.apply(a, []) === "[object Array]") { return "[" + a.map(arrayToString).join(", ") + "]"; } else { return a; } - } + }; /* - Copyright (c) 2011 Andrei Mackenzie - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - function levenshtein(a, b){ - if(a.length == 0) return b.length; - if(b.length == 0) return a.length; + Copyright (c) 2011 Andrei Mackenzie + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + function levenshtein(a, b) { + if (a.length == 0) return b.length; + if (b.length == 0) return a.length; var matrix = []; // increment along the first column of each row var i; - for(i = 0; i <= b.length; i++){ + for (i = 0; i <= b.length; i++) { matrix[i] = [i]; } // increment each column in the first row var j; - for(j = 0; j <= a.length; j++){ + for (j = 0; j <= a.length; j++) { matrix[0][j] = j; } // Fill in the rest of the matrix - for(i = 1; i <= b.length; i++){ - for(j = 1; j <= a.length; j++){ - if(b.charAt(i-1) == a.charAt(j-1)){ - matrix[i][j] = matrix[i-1][j-1]; + for (i = 1; i <= b.length; i++) { + for (j = 1; j <= a.length; j++) { + if (b.charAt(i - 1) == a.charAt(j - 1)) { + matrix[i][j] = matrix[i - 1][j - 1]; } else { - matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution - Math.min(matrix[i][j-1] + 1, // insertion - matrix[i-1][j] + 1)); // deletion + matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution + Math.min(matrix[i][j - 1] + 1, // insertion + matrix[i - 1][j] + 1)); // deletion } } } + return matrix[b.length][a.length]; } + Rematch.levenshtein = levenshtein; - Rematch.distance = function distance(x,y) { - x=x.trim(); - y=y.trim(); - var lev = levenshtein(x,y), - score = lev / (x.length + y.length); + Rematch.distance = function distance(x, y) { + x = x.trim(); + y = y.trim(); + var lev = levenshtein(x, y); + var score = lev / (x.length + y.length); + return score; - } + }; Rematch.rematch = function rematch(distanceFunction) { - function findBestMatch(a, b, cache) { var cachecount = 0; - for(var key in cache) { + for (var key in cache) { cachecount++; } + var bestMatchDist = Infinity; var bestMatch; for (var i = 0; i < a.length; ++i) { @@ -86,25 +90,29 @@ } if (md < bestMatchDist) { bestMatchDist = md; - bestMatch = { indexA: i, indexB: j, score: bestMatchDist }; + bestMatch = {indexA: i, indexB: j, score: bestMatchDist}; } } } + return bestMatch; } - function group(a, b, level, cache) { - if (typeof(cache)==="undefined") { + function group(a, b, level, cache) { + if (typeof(cache) === "undefined") { cache = {}; } - var minLength = Math.min(a.length, b.length); - var bm = findBestMatch(a,b, cache); + + var bm = findBestMatch(a, b, cache); + if (!level) { level = 0; } + if (!bm || (a.length + b.length < 3)) { return [[a, b]]; } + var a1 = a.slice(0, bm.indexA), b1 = b.slice(0, bm.indexB), aMatch = [a[bm.indexA]], @@ -114,21 +122,25 @@ a2 = a.slice(tailA), b2 = b.slice(tailB); - var group1 = group(a1, b1, level+1, cache); - var groupMatch = group(aMatch, bMatch, level+1, cache); - var group2 = group(a2, b2, level+1, cache); + var group1 = group(a1, b1, level + 1, cache); + var groupMatch = group(aMatch, bMatch, level + 1, cache); + var group2 = group(a2, b2, level + 1, cache); var result = groupMatch; + if (bm.indexA > 0 || bm.indexB > 0) { result = group1.concat(result); } - if (a.length > tailA || b.length > tailB ) { + + if (a.length > tailA || b.length > tailB) { result = result.concat(group2); } + return result; } + return group; - } + }; - module.exports['Rematch'] = Rematch; + module.exports.Rematch = Rematch; -})(this); +})(); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index 22b55c8c..6983728f 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { var diffParser = require('./diff-parser.js').DiffParser; var printerUtils = require('./printer-utils.js').PrinterUtils; @@ -63,9 +63,9 @@ '\n'; }; - var matcher=Rematch.rematch(function(a,b) { + var matcher = Rematch.rematch(function(a, b) { var amod = a.content.substr(1), - bmod = b.content.substr(1); + bmod = b.content.substr(1); return Rematch.distance(amod, bmod); }); @@ -94,31 +94,33 @@ var oldLines = []; var newLines = []; + function processChangeBlock() { var matches; var insertType; var deleteType; - var doMatching = config.matching === "lines" || config.matching === "words"; + var doMatching = config.matching === 'lines' || config.matching === 'words'; + if (doMatching) { matches = matcher(oldLines, newLines); insertType = diffParser.LINE_TYPE.INSERT_CHANGES; deleteType = diffParser.LINE_TYPE.DELETE_CHANGES; } else { - matches = [[oldLines,newLines]]; + matches = [[oldLines, newLines]]; insertType = diffParser.LINE_TYPE.INSERTS; deleteType = diffParser.LINE_TYPE.DELETES; } - matches.forEach(function(match){ - var oldLines = match[0]; - var newLines = match[1]; - var tmpHtml; - var j = 0; - var oldLine, newLine, - common = Math.min(oldLines.length, newLines.length), - max = Math.max(oldLines.length, newLines.length); - for (j = 0; j < common; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; + + matches.forEach(function(match) { + oldLines = match[0]; + newLines = match[1]; + + var common = Math.min(oldLines.length, newLines.length); + var max = Math.max(oldLines.length, newLines.length); + + for (var j = 0; j < common; j++) { + var oldLine = oldLines[j]; + var newLine = newLines[j]; config.isCombined = file.isCombined; @@ -130,36 +132,41 @@ fileHtml.right += generateSingleLineHtml(insertType, newLine.newNumber, diff.second.line, diff.second.prefix); - } - if (max > common) { - var oldSlice = oldLines.slice(common), - newSlice = newLines.slice(common); - tmpHtml = processLines(oldLines.slice(common), newLines.slice(common)); - fileHtml.left += tmpHtml.left; - fileHtml.right += tmpHtml.right; - } + } + + if (max > common) { + var oldSlice = oldLines.slice(common); + var newSlice = newLines.slice(common); + + var tmpHtml = processLines(oldSlice, newSlice); + fileHtml.left += tmpHtml.left; + fileHtml.right += tmpHtml.right; + } }); + oldLines = []; newLines = []; } + for (var i = 0; i < block.lines.length; i++) { var line = block.lines[i]; var prefix = line[0]; var escapedLine = utils.escape(line.content.substr(1)); - if ( line.type !== diffParser.LINE_TYPE.INSERTS && - (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { + if (line.type !== diffParser.LINE_TYPE.INSERTS && + (newLines.length > 0 || (line.type !== diffParser.LINE_TYPE.DELETES && oldLines.length > 0))) { 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.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.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); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !!oldLines.length) { + } else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) { newLines.push(line); } else { console.error('unknown state in html side-by-side generator'); @@ -179,21 +186,24 @@ fileHtml.right = ''; var maxLinesNumber = Math.max(oldLines.length, newLines.length); - for (j = 0; j < maxLinesNumber; j++) { - var oldLine = oldLines[j]; - var newLine = newLines[j]; + for (var i = 0; i < maxLinesNumber; i++) { + var oldLine = oldLines[i]; + var newLine = newLines[i]; var oldContent; var newContent; var oldPrefix; var newPrefix; + if (oldLine) { oldContent = utils.escape(oldLine.content.substr(1)); oldPrefix = oldLine.content[0]; } + if (newLine) { newContent = utils.escape(newLine.content.substr(1)); newPrefix = newLine.content[0]; } + if (oldLine && newLine) { fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix); @@ -245,6 +255,6 @@ return fileHtml; } - module.exports['SideBySidePrinter'] = new SideBySidePrinter(); + module.exports.SideBySidePrinter = new SideBySidePrinter(); -})(this); +})(); diff --git a/src/utils.js b/src/utils.js index 7f91ff10..f411a43b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -5,7 +5,7 @@ * */ -(function(ctx, undefined) { +(function() { function Utils() { } @@ -19,7 +19,7 @@ }; 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) { @@ -41,6 +41,6 @@ return value ? value : ''; }; - module.exports['Utils'] = new Utils(); + module.exports.Utils = new Utils(); -})(this); +})(); From 011e06d876922a10c79cac3560d4a90f55ccefdb Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sun, 20 Dec 2015 22:49:50 +0000 Subject: [PATCH 3/3] Remove conflicting CSS --- css/diff2html.css | 30 ++++++++++++++---------------- dist/diff2html.css | 30 ++++++++++++++---------------- dist/diff2html.min.css | 2 +- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/css/diff2html.css b/css/diff2html.css index 7a69479d..3c4ad523 100644 --- a/css/diff2html.css +++ b/css/diff2html.css @@ -42,7 +42,6 @@ color: #399839; border-radius: 5px 0 0 5px; padding: 2px; - width: 25px; } .d2h-lines-deleted { @@ -55,12 +54,10 @@ color: #c33; border-radius: 0 5px 5px 0; padding: 2px; - width: 25px; } .d2h-file-name { display: inline; - height: 33px; line-height: 33px; max-width: 80%; white-space: nowrap; @@ -152,7 +149,6 @@ } .line-num1 { - display: inline-block; float: left; width: 30px; overflow: hidden; @@ -160,7 +156,6 @@ } .line-num2 { - display: inline-block; float: right; width: 30px; overflow: hidden; @@ -169,7 +164,6 @@ .d2h-code-linenumber { position: absolute; - width: 2%; min-width: 65px; padding-left: 10px; padding-right: 10px; @@ -232,10 +226,7 @@ .d2h-file-list-header { font-weight: bold; - margin-bottom: 5px; - text-align: left; - display: inline; - float:left; + float: left; } .d2h-file-list-line { @@ -243,28 +234,31 @@ font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"; } -.d2h-file-list-line .d2h-file-name { +.d2h-file-list-line .d2h-file-name { line-height: 21px; } .d2h-file-list { - display:none; + display: none; } .d2h-clear { - display:block; + display: block; clear: both; } .d2h-del.d2h-change, .d2h-ins.d2h-change { background-color: #ffc; } + ins.d2h-change, del.d2h-change { background-color: #fad771; } + .d2h-file-diff .d2h-del.d2h-change { background-color: #fae1af; } + .d2h-file-diff .d2h-ins.d2h-change { background-color: #ded; } @@ -272,17 +266,21 @@ ins.d2h-change, del.d2h-change { /* CSS only show/hide */ .d2h-show { display: none; - float:left; + float: left; } + .d2h-hide { - float:left; + float: left; } + .d2h-hide:target + .d2h-show { display: inline; } + .d2h-hide:target { display: none; } + .d2h-hide:target ~ .d2h-file-list { - display:block; + display: block; } diff --git a/dist/diff2html.css b/dist/diff2html.css index 7a69479d..3c4ad523 100644 --- a/dist/diff2html.css +++ b/dist/diff2html.css @@ -42,7 +42,6 @@ color: #399839; border-radius: 5px 0 0 5px; padding: 2px; - width: 25px; } .d2h-lines-deleted { @@ -55,12 +54,10 @@ color: #c33; border-radius: 0 5px 5px 0; padding: 2px; - width: 25px; } .d2h-file-name { display: inline; - height: 33px; line-height: 33px; max-width: 80%; white-space: nowrap; @@ -152,7 +149,6 @@ } .line-num1 { - display: inline-block; float: left; width: 30px; overflow: hidden; @@ -160,7 +156,6 @@ } .line-num2 { - display: inline-block; float: right; width: 30px; overflow: hidden; @@ -169,7 +164,6 @@ .d2h-code-linenumber { position: absolute; - width: 2%; min-width: 65px; padding-left: 10px; padding-right: 10px; @@ -232,10 +226,7 @@ .d2h-file-list-header { font-weight: bold; - margin-bottom: 5px; - text-align: left; - display: inline; - float:left; + float: left; } .d2h-file-list-line { @@ -243,28 +234,31 @@ font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"; } -.d2h-file-list-line .d2h-file-name { +.d2h-file-list-line .d2h-file-name { line-height: 21px; } .d2h-file-list { - display:none; + display: none; } .d2h-clear { - display:block; + display: block; clear: both; } .d2h-del.d2h-change, .d2h-ins.d2h-change { background-color: #ffc; } + ins.d2h-change, del.d2h-change { background-color: #fad771; } + .d2h-file-diff .d2h-del.d2h-change { background-color: #fae1af; } + .d2h-file-diff .d2h-ins.d2h-change { background-color: #ded; } @@ -272,17 +266,21 @@ ins.d2h-change, del.d2h-change { /* CSS only show/hide */ .d2h-show { display: none; - float:left; + float: left; } + .d2h-hide { - float:left; + float: left; } + .d2h-hide:target + .d2h-show { display: inline; } + .d2h-hide:target { display: none; } + .d2h-hide:target ~ .d2h-file-list { - display:block; + display: block; } diff --git a/dist/diff2html.min.css b/dist/diff2html.min.css index 2981be9c..c45a1018 100644 --- a/dist/diff2html.min.css +++ b/dist/diff2html.min.css @@ -1 +1 @@ -.d2h-wrapper{display:block;margin:0 auto;text-align:left;width:100%}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-file-header{padding:5px 10px;border-bottom:1px solid #d8d8d8;background-color:#f7f7f7;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-stats{display:inline;font-size:12px;text-align:center;max-width:15%}.d2h-lines-added{text-align:right}.d2h-lines-added>*{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px;width:25px}.d2h-lines-deleted{text-align:left}.d2h-lines-deleted>*{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px;width:25px}.d2h-file-name{display:inline;height:33px;line-height:33px;max-width:80%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;height:18px;line-height:18px;width:100%}.d2h-files-diff{width:100%}.d2h-file-diff{overflow-x:scroll;overflow-y:hidden}.d2h-file-side-diff{display:inline-block;overflow-x:scroll;overflow-y:hidden;width:50%;margin-right:-4px}.d2h-code-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:80px;color:inherit;overflow-x:inherit;background:none}.d2h-code-side-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:50px;color:inherit;overflow-x:inherit;background:none}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#ffb6ba;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#97f295;border-radius:.2em}.d2h-code-line-prefix{float:left;background:none;padding:0}.d2h-code-line-ctn{background:none;padding:0}.line-num1{display:inline-block;float:left;width:30px;overflow:hidden;text-overflow:ellipsis}.line-num2{display:inline-block;float:right;width:30px;overflow:hidden;text-overflow:ellipsis}.d2h-code-linenumber{position:absolute;width:2%;min-width:65px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,0.3);text-align:right;border:solid #eeeeee;border-width:0 1px 0 1px;cursor:pointer}.d2h-code-side-linenumber{position:absolute;width:35px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,0.3);text-align:right;border:solid #eeeeee;border-width:0 1px 0 1px;cursor:pointer;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#fee8e9;border-color:#e9aeae}.d2h-ins{background-color:#dfd;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,0.3);border-color:#d5e4f2}.d2h-file-list-wrapper{margin-bottom:10px;padding:0 10px}.d2h-file-list-wrapper a{text-decoration:none;color:#3572b0}.d2h-file-list-wrapper a:visited{color:#3572b0}.d2h-file-list-header{font-weight:bold;margin-bottom:5px;text-align:left;display:inline;float:left}.d2h-file-list-line{text-align:left;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-list-line .d2h-file-name{line-height:21px}.d2h-file-list{display:none}.d2h-clear{display:block;clear:both}.d2h-del.d2h-change,.d2h-ins.d2h-change{background-color:#ffc}ins.d2h-change,del.d2h-change{background-color:#fad771}.d2h-file-diff .d2h-del.d2h-change{background-color:#fae1af}.d2h-file-diff .d2h-ins.d2h-change{background-color:#ded}.d2h-show{display:none;float:left}.d2h-hide{float:left}.d2h-hide:target+.d2h-show{display:inline}.d2h-hide:target{display:none}.d2h-hide:target~.d2h-file-list{display:block} \ No newline at end of file +.d2h-wrapper{display:block;margin:0 auto;text-align:left;width:100%}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-file-header{padding:5px 10px;border-bottom:1px solid #d8d8d8;background-color:#f7f7f7;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-stats{display:inline;font-size:12px;text-align:center;max-width:15%}.d2h-lines-added{text-align:right}.d2h-lines-added>*{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px}.d2h-lines-deleted{text-align:left}.d2h-lines-deleted>*{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px}.d2h-file-name{display:inline;line-height:33px;max-width:80%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;height:18px;line-height:18px;width:100%}.d2h-files-diff{width:100%}.d2h-file-diff{overflow-x:scroll;overflow-y:hidden}.d2h-file-side-diff{display:inline-block;overflow-x:scroll;overflow-y:hidden;width:50%;margin-right:-4px}.d2h-code-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:80px;color:inherit;overflow-x:inherit;background:none}.d2h-code-side-line{display:block;white-space:pre;padding:0 10px;height:18px;line-height:18px;margin-left:50px;color:inherit;overflow-x:inherit;background:none}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#ffb6ba;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#97f295;border-radius:.2em}.d2h-code-line-prefix{float:left;background:none;padding:0}.d2h-code-line-ctn{background:none;padding:0}.line-num1{float:left;width:30px;overflow:hidden;text-overflow:ellipsis}.line-num2{float:right;width:30px;overflow:hidden;text-overflow:ellipsis}.d2h-code-linenumber{position:absolute;min-width:65px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,0.3);text-align:right;border:solid #eeeeee;border-width:0 1px 0 1px;cursor:pointer}.d2h-code-side-linenumber{position:absolute;width:35px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,0.3);text-align:right;border:solid #eeeeee;border-width:0 1px 0 1px;cursor:pointer;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#fee8e9;border-color:#e9aeae}.d2h-ins{background-color:#dfd;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,0.3);border-color:#d5e4f2}.d2h-file-list-wrapper{margin-bottom:10px;padding:0 10px}.d2h-file-list-wrapper a{text-decoration:none;color:#3572b0}.d2h-file-list-wrapper a:visited{color:#3572b0}.d2h-file-list-header{font-weight:bold;float:left}.d2h-file-list-line{text-align:left;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-list-line .d2h-file-name{line-height:21px}.d2h-file-list{display:none}.d2h-clear{display:block;clear:both}.d2h-del.d2h-change,.d2h-ins.d2h-change{background-color:#ffc}ins.d2h-change,del.d2h-change{background-color:#fad771}.d2h-file-diff .d2h-del.d2h-change{background-color:#fae1af}.d2h-file-diff .d2h-ins.d2h-change{background-color:#ded}.d2h-show{display:none;float:left}.d2h-hide{float:left}.d2h-hide:target+.d2h-show{display:inline}.d2h-hide:target{display:none}.d2h-hide:target~.d2h-file-list{display:block} \ No newline at end of file