From de13e9506c4eb655d1ef862f76e9ffe6f45302ed Mon Sep 17 00:00:00 2001 From: Rodrigo Fernandes Date: Sat, 8 Aug 2015 01:11:35 +0100 Subject: [PATCH] use webpack for the browser * add webpack bundling * clean bower dependencies since we are using webpack * add jscs node style support --- bin/diff2html | 3 - bower.json | 18 +- config.jscs.json | 49 + dist/diff2html.js | 3004 ++++++++++++++++++----------------- dist/diff2html.min.js | 2 +- lib/diff.js | 643 -------- lib/fakeRequire.js | 20 - package.json | 59 +- release.sh | 18 +- sample/index.html | 21 +- src/diff-parser.js | 76 +- src/diff2html.js | 28 +- src/html-printer.js | 14 +- src/line-by-line-printer.js | 145 +- src/printer-utils.js | 51 +- src/side-by-side-printer.js | 188 +-- src/utils.js | 26 +- 17 files changed, 1871 insertions(+), 2494 deletions(-) delete mode 100755 bin/diff2html create mode 100644 config.jscs.json delete mode 100644 lib/diff.js delete mode 100644 lib/fakeRequire.js diff --git a/bin/diff2html b/bin/diff2html deleted file mode 100755 index e32f086..0000000 --- a/bin/diff2html +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node - -require("../src/diff2html.js"); diff --git a/bower.json b/bower.json index bc920b6..8d00c1c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "diff2html", - "version": "0.2.5-1", + "version": "1.0.0-1", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [ @@ -20,37 +20,25 @@ "difftohtml", "colorized" ], - "authors": [ "Rodrigo Fernandes " ], - "repository": { "type": "git", "url": "git://github.com/rtfpessoa/diff2html.git" }, - "main": "./src/diff2html.js", - "license": "MIT", - "moduleType": [ "globals", "node" ], - - "dependencies": { - "jsdiff": ">= 1.4.0" - }, - "ignore": [ "**/.*", "node_modules", "bower_components", - "test", - "tests", - "bin", "package.json", - "release.sh" + "release.sh", + "config.jscs.json" ] } diff --git a/config.jscs.json b/config.jscs.json new file mode 100644 index 0000000..17dec03 --- /dev/null +++ b/config.jscs.json @@ -0,0 +1,49 @@ +{ + "disallowKeywords": [ + "with" + ], + "disallowKeywordsOnNewLine": [ + "else" + ], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleVarDecl": "exceptUndefined", + "disallowNewlineBeforeBlockStatements": true, + "disallowQuotedKeysInObjects": true, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpacesInFunction": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideParentheses": true, + "disallowTrailingWhitespace": true, + "maximumLineLength": 120, + "requireCamelCaseOrUpperCaseIdentifiers": true, + "requireCapitalizedComments": true, + "requireCapitalizedConstructors": true, + "requireCurlyBraces": true, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "case", + "return", + "try", + "catch", + "typeof" + ], + "requireSpaceAfterLineComment": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBeforeObjectValues": true, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "requireTrailingComma": null, + "validateIndentation": 2, + "validateLineBreaks": "LF", + "validateQuoteMarks": "'" +} diff --git a/dist/diff2html.js b/dist/diff2html.js index 2d88923..e549362 100644 --- a/dist/diff2html.js +++ b/dist/diff2html.js @@ -1,1479 +1,1525 @@ -// Diff2Html minifier version (automatically generated) -/* - * Hack to allow nodejs require("package/file") in the browser - * How? - * Since every require is used as an object: - * `require("./utils.js").Utils` // (notice the `.Utils`) - * - * We can say that when there is no require method - * we use the global object in which the `Utils` - * object was already injected. - */ - -var $globalHolder = (typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof this !== 'undefined' && this) || - Function('return this')(); -function require() { - return $globalHolder; -} -/* See LICENSE file for terms of use */ - -/* - * Text diff implementation. - * - * This library supports the following APIS: - * JsDiff.diffChars: Character by character diff - * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace - * JsDiff.diffLines: Line based diff - * - * JsDiff.diffCss: Diff targeted at CSS content - * - * These methods are based on the implementation proposed in - * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986). - * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 - */ -(function (global, undefined) { - var objectPrototypeToString = Object.prototype.toString; - - /*istanbul ignore next*/ - function map(arr, mapper, that) { - if (Array.prototype.map) { - return Array.prototype.map.call(arr, mapper, that); - } - - var other = new Array(arr.length); - - for (var i = 0, n = arr.length; i < n; i++) { - other[i] = mapper.call(that, arr[i], i, arr); - } - return other; - } - - function clonePath(path) { - return {newPos: path.newPos, components: path.components.slice(0)}; - } - - function removeEmpty(array) { - var ret = []; - for (var i = 0; i < array.length; i++) { - if (array[i]) { - ret.push(array[i]); - } - } - return ret; - } - - function escapeHTML(s) { - var n = s; - n = n.replace(/&/g, '&'); - n = n.replace(//g, '>'); - n = n.replace(/"/g, '"'); - - return n; - } - - // This function handles the presence of circular references by bailing out when encountering an - // object that is already on the "stack" of items being processed. - function canonicalize(obj, stack, replacementStack) { - stack = stack || []; - replacementStack = replacementStack || []; - - var i; - - for (i = 0; i < stack.length; i += 1) { - if (stack[i] === obj) { - return replacementStack[i]; - } - } - - var canonicalizedObj; - - if ('[object Array]' === objectPrototypeToString.call(obj)) { - stack.push(obj); - canonicalizedObj = new Array(obj.length); - replacementStack.push(canonicalizedObj); - for (i = 0; i < obj.length; i += 1) { - canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack); - } - stack.pop(); - replacementStack.pop(); - } else if (typeof obj === 'object' && obj !== null) { - stack.push(obj); - canonicalizedObj = {}; - replacementStack.push(canonicalizedObj); - var sortedKeys = [], - key; - for (key in obj) { - sortedKeys.push(key); - } - sortedKeys.sort(); - for (i = 0; i < sortedKeys.length; i += 1) { - key = sortedKeys[i]; - canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack); - } - stack.pop(); - replacementStack.pop(); - } else { - canonicalizedObj = obj; - } - return canonicalizedObj; - } - - function buildValues(components, newString, oldString, useLongestToken) { - var componentPos = 0, - componentLen = components.length, - newPos = 0, - oldPos = 0; - - for (; componentPos < componentLen; componentPos++) { - var component = components[componentPos]; - if (!component.removed) { - if (!component.added && useLongestToken) { - var value = newString.slice(newPos, newPos + component.count); - value = map(value, 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; - - // Common case - if (!component.added) { - oldPos += component.count; - } - } else { - component.value = oldString.slice(oldPos, oldPos + component.count).join(''); - oldPos += component.count; - - // Reverse add and remove so removes are output first to match common convention - // The diffing algorithm is tied to add then remove output and this is the simplest - // route to get the desired output with minimal overhead. - if (componentPos && components[componentPos - 1].added) { - var tmp = components[componentPos - 1]; - components[componentPos - 1] = components[componentPos]; - components[componentPos] = tmp; - } - } - } - - return components; - } - - function Diff(ignoreWhitespace) { - this.ignoreWhitespace = ignoreWhitespace; - } - - Diff.prototype = { - diff: function (oldString, newString, callback) { - var self = this; - - function done(value) { - if (callback) { - setTimeout(function () { - callback(undefined, value); - }, 0); - return true; - } else { - return value; - } - } - - // Handle the identity case (this is due to unrolling editLength == 0 - if (newString === oldString) { - return done([{value: newString}]); - } - if (!newString) { - return done([{value: oldString, removed: true}]); - } - if (!oldString) { - return done([{value: newString, added: true}]); - } - - newString = this.tokenize(newString); - oldString = this.tokenize(oldString); - - var newLen = newString.length, oldLen = oldString.length; - var editLength = 1; - var maxEditLength = newLen + oldLen; - var bestPath = [{newPos: -1, components: []}]; - - // Seed editLength = 0, i.e. the content starts with the same values - var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0); - if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) { - // Identity per the equality and tokenizer - return done([{value: newString.join('')}]); - } - - // Main worker method. checks all permutations of a given edit length for acceptance. - function execEditLength() { - for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) { - var basePath; - var addPath = bestPath[diagonalPath - 1], - removePath = bestPath[diagonalPath + 1], - oldPos = (removePath ? removePath.newPos : 0) - diagonalPath; - if (addPath) { - // No one else is going to attempt to use this value, clear it - bestPath[diagonalPath - 1] = undefined; - } - - var canAdd = addPath && addPath.newPos + 1 < newLen, - canRemove = removePath && 0 <= oldPos && oldPos < oldLen; - if (!canAdd && !canRemove) { - // If this path is a terminal then prune - bestPath[diagonalPath] = undefined; - continue; - } - - // Select the diagonal that we want to branch from. We select the prior - // path whose position in the new string is the farthest from the origin - // and does not pass the bounds of the diff graph - if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) { - basePath = clonePath(removePath); - self.pushComponent(basePath.components, undefined, true); - } else { - basePath = addPath; // No need to clone, we've pulled it from the list - basePath.newPos++; - self.pushComponent(basePath.components, true, undefined); - } - - oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); - - // If we have hit the end of both strings, then we are done - if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) { - return done(buildValues(basePath.components, newString, oldString, self.useLongestToken)); - } else { - // Otherwise track this path as a potential candidate and continue. - bestPath[diagonalPath] = basePath; - } - } - - editLength++; - } - - // Performs the length of edit iteration. Is a bit fugly as this has to support the - // sync and async mode which is never fun. Loops over execEditLength until a value - // is produced. - if (callback) { - (function exec() { - setTimeout(function () { - // This should not happen, but we want to be safe. - /*istanbul ignore next */ - if (editLength > maxEditLength) { - return callback(); - } - - if (!execEditLength()) { - exec(); - } - }, 0); - }()); - } else { - while (editLength <= maxEditLength) { - var ret = execEditLength(); - if (ret) { - return ret; - } - } - } - }, - - pushComponent: function (components, added, removed) { - var last = components[components.length - 1]; - if (last && last.added === added && last.removed === removed) { - // We need to clone here as the component clone operation is just - // as shallow array clone - components[components.length - 1] = {count: last.count + 1, added: added, removed: removed}; - } else { - components.push({count: 1, added: added, removed: removed}); - } - }, - extractCommon: function (basePath, newString, oldString, diagonalPath) { - var newLen = newString.length, - oldLen = oldString.length, - newPos = basePath.newPos, - oldPos = newPos - diagonalPath, - - commonCount = 0; - while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) { - newPos++; - oldPos++; - commonCount++; - } - - if (commonCount) { - basePath.components.push({count: commonCount}); - } - - basePath.newPos = newPos; - return oldPos; - }, - - equals: function (left, right) { - var reWhitespace = /\S/; - return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)); - }, - tokenize: function (value) { - return value.split(''); - } - }; - - var CharDiff = new Diff(); - - var WordDiff = new Diff(true); - var WordWithSpaceDiff = new Diff(); - WordDiff.tokenize = WordWithSpaceDiff.tokenize = function (value) { - return removeEmpty(value.split(/(\s+|\b)/)); - }; - - var CssDiff = new Diff(true); - CssDiff.tokenize = function (value) { - return removeEmpty(value.split(/([{}:;,]|\s+)/)); - }; - - var LineDiff = new Diff(); - - var TrimmedLineDiff = new Diff(); - TrimmedLineDiff.ignoreTrim = true; - - LineDiff.tokenize = TrimmedLineDiff.tokenize = function (value) { - var retLines = [], - lines = value.split(/^/m); - for (var i = 0; i < lines.length; i++) { - var line = lines[i], - lastLine = lines[i - 1], - lastLineLastChar = lastLine && lastLine[lastLine.length - 1]; - - // Merge lines that may contain windows new lines - if (line === '\n' && lastLineLastChar === '\r') { - retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n'; - } else { - if (this.ignoreTrim) { - line = line.trim(); - // add a newline unless this is the last line. - if (i < lines.length - 1) { - line += '\n'; - } - } - retLines.push(line); - } - } - - return retLines; - }; - - var PatchDiff = new Diff(); - PatchDiff.tokenize = function (value) { - var ret = [], - linesAndNewlines = value.split(/(\n|\r\n)/); - - // Ignore the final empty token that occurs if the string ends with a new line - if (!linesAndNewlines[linesAndNewlines.length - 1]) { - linesAndNewlines.pop(); - } - - // Merge the content and line separators into single tokens - for (var i = 0; i < linesAndNewlines.length; i++) { - var line = linesAndNewlines[i]; - - if (i % 2) { - ret[ret.length - 1] += line; - } else { - ret.push(line); - } - } - return ret; - }; - - var SentenceDiff = new Diff(); - SentenceDiff.tokenize = function (value) { - return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/)); - }; - - var JsonDiff = new Diff(); - // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a - // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output: - JsonDiff.useLongestToken = true; - JsonDiff.tokenize = LineDiff.tokenize; - JsonDiff.equals = function (left, right) { - return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1')); - }; - - var JsDiff = { - Diff: Diff, - - diffChars: function (oldStr, newStr, callback) { - return CharDiff.diff(oldStr, newStr, callback); - }, - diffWords: function (oldStr, newStr, callback) { - return WordDiff.diff(oldStr, newStr, callback); - }, - diffWordsWithSpace: function (oldStr, newStr, callback) { - return WordWithSpaceDiff.diff(oldStr, newStr, callback); - }, - diffLines: function (oldStr, newStr, callback) { - return LineDiff.diff(oldStr, newStr, callback); - }, - diffTrimmedLines: function (oldStr, newStr, callback) { - return TrimmedLineDiff.diff(oldStr, newStr, callback); - }, - - diffSentences: function (oldStr, newStr, callback) { - return SentenceDiff.diff(oldStr, newStr, callback); - }, - - diffCss: function (oldStr, newStr, callback) { - return CssDiff.diff(oldStr, newStr, callback); - }, - diffJson: function (oldObj, newObj, callback) { - return JsonDiff.diff( - typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '), - typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '), - callback - ); - }, - - createTwoFilesPatch: function (oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) { - var ret = []; - - if (oldFileName == newFileName) { - ret.push('Index: ' + oldFileName); - } - ret.push('==================================================================='); - ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader)); - ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader)); - - var diff = PatchDiff.diff(oldStr, newStr); - diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier - - // Formats a given set of lines for printing as context lines in a patch - function contextLines(lines) { - return map(lines, function (entry) { - return ' ' + entry; - }); - } - - // Outputs the no newline at end of file warning if needed - function eofNL(curRange, i, current) { - var last = diff[diff.length - 2], - isLast = i === diff.length - 2, - isLastOfType = i === diff.length - 3 && current.added !== last.added; - - // Figure out if this is the last line for the given file and missing NL - if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) { - curRange.push('\\ No newline at end of file'); - } - } - - var oldRangeStart = 0, newRangeStart = 0, curRange = [], - oldLine = 1, newLine = 1; - for (var i = 0; i < diff.length; i++) { - var current = diff[i], - lines = current.lines || current.value.replace(/\n$/, '').split('\n'); - current.lines = lines; - - if (current.added || current.removed) { - // If we have previous context, start with that - if (!oldRangeStart) { - var prev = diff[i - 1]; - oldRangeStart = oldLine; - newRangeStart = newLine; - - if (prev) { - curRange = contextLines(prev.lines.slice(-4)); - oldRangeStart -= curRange.length; - newRangeStart -= curRange.length; - } - } - - // Output our changes - curRange.push.apply(curRange, map(lines, function (entry) { - return (current.added ? '+' : '-') + entry; - })); - eofNL(curRange, i, current); - - // Track the updated file position - if (current.added) { - newLine += lines.length; - } else { - oldLine += lines.length; - } - } else { - // Identical context lines. Track line changes - if (oldRangeStart) { - // Close out any changes that have been output (or join overlapping) - if (lines.length <= 8 && i < diff.length - 2) { - // Overlapping - curRange.push.apply(curRange, contextLines(lines)); - } else { - // end the range and output - var contextSize = Math.min(lines.length, 4); - ret.push( - '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize) - + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize) - + ' @@'); - ret.push.apply(ret, curRange); - ret.push.apply(ret, contextLines(lines.slice(0, contextSize))); - if (lines.length <= 4) { - eofNL(ret, i, current); - } - - oldRangeStart = 0; - newRangeStart = 0; - curRange = []; - } - } - oldLine += lines.length; - newLine += lines.length; - } - } - - return ret.join('\n') + '\n'; - }, - - createPatch: function (fileName, oldStr, newStr, oldHeader, newHeader) { - return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader); - }, - - applyPatch: function (oldStr, uniDiff) { - var diffstr = uniDiff.split('\n'), - hunks = [], - i = 0, - remEOFNL = false, - addEOFNL = false; - - // Skip to the first change hunk - while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) { - i++; - } - - // Parse the unified diff - for (; i < diffstr.length; i++) { - if (diffstr[i][0] === '@') { - var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/); - hunks.unshift({ - start: chnukHeader[3], - oldlength: +chnukHeader[2], - removed: [], - newlength: chnukHeader[4], - added: [] - }); - } else if (diffstr[i][0] === '+') { - hunks[0].added.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === '-') { - hunks[0].removed.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === ' ') { - hunks[0].added.push(diffstr[i].substr(1)); - hunks[0].removed.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === '\\') { - if (diffstr[i - 1][0] === '+') { - remEOFNL = true; - } else if (diffstr[i - 1][0] === '-') { - addEOFNL = true; - } - } - } - - // Apply the diff to the input - var lines = oldStr.split('\n'); - for (i = hunks.length - 1; i >= 0; i--) { - var hunk = hunks[i]; - // Sanity check the input string. Bail if we don't match. - for (var j = 0; j < hunk.oldlength; j++) { - if (lines[hunk.start - 1 + j] !== hunk.removed[j]) { - return false; - } - } - Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added)); - } - - // Handle EOFNL insertion/removal - if (remEOFNL) { - while (!lines[lines.length - 1]) { - lines.pop(); - } - } else if (addEOFNL) { - lines.push(''); - } - return lines.join('\n'); - }, - - convertChangesToXML: function (changes) { - var ret = []; - for (var i = 0; i < changes.length; i++) { - var change = changes[i]; - if (change.added) { - ret.push(''); - } else if (change.removed) { - ret.push(''); - } - - ret.push(escapeHTML(change.value)); - - if (change.added) { - ret.push(''); - } else if (change.removed) { - ret.push(''); - } - } - return ret.join(''); - }, - - // See: http://code.google.com/p/google-diff-match-patch/wiki/API - convertChangesToDMP: function (changes) { - var ret = [], - change, - operation; - for (var i = 0; i < changes.length; i++) { - change = changes[i]; - if (change.added) { - operation = 1; - } else if (change.removed) { - operation = -1; - } else { - operation = 0; - } - - ret.push([operation, change.value]); - } - return ret; - }, - - canonicalize: canonicalize - }; - - /*istanbul ignore next */ - /*global module */ - if (typeof module !== 'undefined' && module.exports) { - module.exports = JsDiff; - } else if (typeof define === 'function' && define.amd) { - /*global define */ - define([], function () { - return JsDiff; - }); - } else if (typeof global.JsDiff === 'undefined') { - global.JsDiff = JsDiff; - } -}(this)); -/* - * - * Utils (utils.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - function Utils() { - } - - Utils.prototype.escape = function (str) { - return str.slice(0) - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/\t/g, " "); - }; - - Utils.prototype.startsWith = function (str, start) { - return str.indexOf(start) === 0; - }; - - Utils.prototype.valueOrEmpty = function (value) { - return value ? value : ""; - }; - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["Utils"] = new Utils(); - -})(this); -/* - * - * Diff Parser (diff-parser.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - var utils = require("./utils.js").Utils; - - var LINE_TYPE = { - INSERTS: "d2h-ins", - DELETES: "d2h-del", - CONTEXT: "d2h-cntx", - INFO: "d2h-info" - }; - - function DiffParser() { - } - - DiffParser.prototype.LINE_TYPE = LINE_TYPE; - - DiffParser.prototype.generateDiffJson = function (diffInput) { - var files = [], - currentFile = null, - currentBlock = null, - oldLine = null, - newLine = null; - - var saveBlock = function () { - /* add previous block(if exists) before start a new file */ - if (currentBlock) { - currentFile.blocks.push(currentBlock); - currentBlock = null; - } - }; - - var saveFile = function () { - /* - * add previous file(if exists) before start a new one - * if it has name (to avoid binary files errors) - */ - if (currentFile && currentFile.newName) { - files.push(currentFile); - currentFile = null; - } - }; - - var startFile = function () { - saveBlock(); - saveFile(); - - /* create file structure */ - currentFile = {}; - currentFile.blocks = []; - currentFile.deletedLines = 0; - currentFile.addedLines = 0; - }; - - var startBlock = function (line) { - saveBlock(); - - var values; - - if (values = /^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line)) { - currentFile.isCombined = false; - } else if (values = /^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line)) { - currentFile.isCombined = true; - } else { - values = [0, 0]; - currentFile.isCombined = false; - } - - oldLine = values[1]; - newLine = values[2]; - - /* create block metadata */ - currentBlock = {}; - currentBlock.lines = []; - currentBlock.oldStartLine = oldLine; - currentBlock.newStartLine = newLine; - currentBlock.header = line; - }; - - var createLine = function (line) { - var currentLine = {}; - currentLine.content = line; - - /* fill the line data */ - if (utils.startsWith(line, "+") || utils.startsWith(line, " +")) { - currentFile.addedLines++; - - currentLine.type = LINE_TYPE.INSERTS; - currentLine.oldNumber = null; - currentLine.newNumber = newLine++; - - currentBlock.lines.push(currentLine); - - } else if (utils.startsWith(line, "-") || utils.startsWith(line, " -")) { - currentFile.deletedLines++; - - currentLine.type = LINE_TYPE.DELETES; - currentLine.oldNumber = oldLine++; - currentLine.newNumber = null; - - currentBlock.lines.push(currentLine); - - } else { - currentLine.type = LINE_TYPE.CONTEXT; - currentLine.oldNumber = oldLine++; - currentLine.newNumber = newLine++; - - currentBlock.lines.push(currentLine); - } - }; - - var diffLines = diffInput.split("\n"); - diffLines.forEach(function (line) { - // Unmerged paths, and possibly other non-diffable files - // https://github.com/scottgonzalez/pretty-diff/issues/11 - // Also, remove some useless lines - if (!line || utils.startsWith(line, "*")) { - //|| utils.startsWith(line, "new") || utils.startsWith(line, "index") - return; - } - - /* Diff */ - var oldMode = /^old mode (\d{6})/; - var newMode = /^new mode (\d{6})/; - var deletedFileMode = /^deleted file mode (\d{6})/; - var newFileMode = /^new file mode (\d{6})/; - - var copyFrom = /^copy from (.+)/; - var copyTo = /^copy to (.+)/; - - var renameFrom = /^rename from (.+)/; - var renameTo = /^rename to (.+)/; - - var similarityIndex = /^similarity index (\d+)%/; - var dissimilarityIndex = /^dissimilarity index (\d+)%/; - var index = /^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/; - - /* Combined Diff */ - var combinedIndex = /^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/; - var combinedMode = /^mode (\d{6}),(\d{6})..(\d{6})/; - var combinedNewFile = /^new file mode (\d{6})/; - var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; - - var values = []; - if (utils.startsWith(line, "diff")) { - startFile(); - } else if (currentFile && !currentFile.oldName && (values = /^--- a\/(\S+).*$/.exec(line))) { - currentFile.oldName = values[1]; - currentFile.language = getExtension(currentFile.oldName, currentFile.language); - } else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [b]?\/(\S+).*$/.exec(line))) { - currentFile.newName = values[1]; - currentFile.language = getExtension(currentFile.newName, currentFile.language); - } else if (currentFile && utils.startsWith(line, "@@")) { - startBlock(line); - } else if ((values = oldMode.exec(line))) { - currentFile.oldMode = values[1]; - } else if ((values = newMode.exec(line))) { - currentFile.newMode = values[1]; - } else if ((values = deletedFileMode.exec(line))) { - currentFile.deletedFileMode = values[1]; - } else if ((values = newFileMode.exec(line))) { - currentFile.newFileMode = values[1]; - } else if ((values = copyFrom.exec(line))) { - currentFile.oldName = values[1]; - currentFile.isCopy = true; - } else if ((values = copyTo.exec(line))) { - currentFile.newName = values[1]; - currentFile.isCopy = true; - } else if ((values = renameFrom.exec(line))) { - currentFile.oldName = values[1]; - currentFile.isRename = true; - } else if ((values = renameTo.exec(line))) { - currentFile.newName = values[1]; - currentFile.isRename = true; - } else if ((values = similarityIndex.exec(line))) { - currentFile.unchangedPercentage = values[1]; - } else if ((values = dissimilarityIndex.exec(line))) { - currentFile.changedPercentage = values[1]; - } else if ((values = index.exec(line))) { - currentFile.checksumBefore = values[1]; - currentFile.checksumAfter = values[2]; - values[2] && (currentFile.mode = values[3]); - } else if ((values = combinedIndex.exec(line))) { - currentFile.checksumBefore = [values[2], values[3]]; - currentFile.checksumAfter = values[1]; - } else if ((values = combinedMode.exec(line))) { - currentFile.oldMode = [values[2], values[3]]; - currentFile.newMode = values[1]; - } else if ((values = combinedNewFile.exec(line))) { - currentFile.newFileMode = values[1]; - } else if ((values = combinedDeletedFile.exec(line))) { - currentFile.deletedFileMode = values[1]; - } else if (currentBlock) { - createLine(line); - } - }); - - saveBlock(); - saveFile(); - - return files; - }; - - function getExtension(filename, language) { - var nameSplit = filename.split("."); - if (nameSplit.length > 1) return nameSplit[nameSplit.length - 1]; - else return language; - } - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["DiffParser"] = new DiffParser(); - -})(this); -/* - * - * PrinterUtils (printer-utils.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - // dirty hack for browser compatibility - var jsDiff = (typeof JsDiff !== "undefined" && JsDiff) || require("diff"); - var utils = require("./utils.js").Utils; - - function PrinterUtils() { - } - - PrinterUtils.prototype.getDiffName = function (file) { - var oldFilename = file.oldName; - var newFilename = file.newName; - - 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"; - } - }; - - PrinterUtils.prototype.diffHighlight = function (diffLine1, diffLine2, config) { - var lineStart1, lineStart2; - - var prefixSize = 1; - - if (config.isCombined) prefixSize = 2; - - lineStart1 = diffLine1.substr(0, prefixSize); - lineStart2 = diffLine2.substr(0, prefixSize); - - diffLine1 = diffLine1.substr(prefixSize); - diffLine2 = diffLine2.substr(prefixSize); - - var diff; - if (config.charByChar) diff = jsDiff.diffChars(diffLine1, diffLine2); - else diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); - - var highlightedLine = ""; - - diff.forEach(function (part) { - var elemType = part.added ? 'ins' : part.removed ? 'del' : null; - var escapedValue = utils.escape(part.value); - - if (elemType !== null) highlightedLine += "<" + elemType + ">" + escapedValue + ""; - else highlightedLine += escapedValue; - }); - - return { - first: { - prefix: lineStart1, - line: removeIns(highlightedLine) - }, - second: { - prefix: lineStart2, - line: removeDel(highlightedLine) - } - } - }; - - function isDeletedName(name) { - return name === "dev/null"; - } - - function removeIns(line) { - return line.replace(/(((.|\n)*?)<\/ins>)/g, ""); - } - - function removeDel(line) { - return line.replace(/(((.|\n)*?)<\/del>)/g, ""); - } - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["PrinterUtils"] = new PrinterUtils(); - -})(this); -/* - * - * HtmlPrinter (html-printer.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - var diffParser = require("./diff-parser.js").DiffParser; - var printerUtils = require("./printer-utils.js").PrinterUtils; - var utils = require("./utils.js").Utils; - - function SideBySidePrinter() { - } - - SideBySidePrinter.prototype.generateSideBySideJsonHtml = function (diffFiles, config) { - return "
\n" + - diffFiles.map(function (file) { - - var diffs; - if (file.blocks.length) diffs = generateSideBySideFileHtml(file, config); - else diffs = generateEmptyDiff(); - - return "
\n" + - "
\n" + - "
\n" + - " +" + file.addedLines + "\n" + - " -" + file.deletedLines + "\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"; - }; - - function generateSideBySideFileHtml(file, config) { - var fileHtml = {}; - fileHtml.left = ""; - fileHtml.right = ""; - - file.blocks.forEach(function (block) { - - fileHtml.left += "\n" + - " \n" + - " " + - "
" + utils.escape(block.header) + "
" + - " \n" + - "\n"; - - fileHtml.right += "\n" + - " \n" + - " " + - "
" + - " \n" + - "\n"; - - var oldLines = [], newLines = []; - var tmpHtml = ""; - - for (var i = 0; i < block.lines.length; i++) { - var line = block.lines[i]; - var escapedLine = utils.escape(line.content); - - if (line.type == diffParser.LINE_TYPE.CONTEXT && !oldLines.length && !newLines.length) { - fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine); - fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) { - fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); - fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) { - oldLines.push(line); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && oldLines.length > newLines.length) { - newLines.push(line); - } else { - var j = 0; - var oldLine, newLine; - - if (oldLines.length === newLines.length) { - for (j = 0; j < oldLines.length; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; - - config.isCombined = file.isCombined; - - var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); - - fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, diff.first.line, diff.first.prefix); - fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, diff.second.line, diff.second.prefix); - } - } else { - tmpHtml = processLines(oldLines, newLines); - fileHtml.left += tmpHtml.left; - fileHtml.right += tmpHtml.right; - } - - oldLines = []; - newLines = []; - i--; - } - } - - tmpHtml = processLines(oldLines, newLines); - fileHtml.left += tmpHtml.left; - fileHtml.right += tmpHtml.right; - }); - - return fileHtml; - } - - function processLines(oldLines, newLines) { - var fileHtml = {}; - fileHtml.left = ""; - fileHtml.right = ""; - - var maxLinesNumber = Math.max(oldLines.length, newLines.length); - for (j = 0; j < maxLinesNumber; j++) { - var oldLine = oldLines[j]; - var newLine = newLines[j]; - - if (oldLine && newLine) { - fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content)); - fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); - } else if (oldLine) { - fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content)); - fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); - } else if (newLine) { - fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); - fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); - } else { - console.error("How did it get here?"); - } - } - - return fileHtml; - } - - function generateSingleLineHtml(type, number, content, prefix) { - var htmlPrefix = ""; - if (prefix) htmlPrefix = "" + prefix + ""; - - var htmlContent = ""; - if (content) htmlContent = "" + content + ""; - - return "\n" + - " " + number + "\n" + - " " + - "
" + htmlPrefix + htmlContent + "
" + - " \n" + - " \n"; - } - - function generateEmptyDiff() { - var fileHtml = {}; - fileHtml.right = ""; - - fileHtml.left = "\n" + - " " + - "
" + - "File without changes" + - "
" + - " \n" + - "\n"; - - return fileHtml; - } - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["SideBySidePrinter"] = new SideBySidePrinter(); - -})(this); -/* - * - * LineByLinePrinter (line-by-line-printer.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - var diffParser = require("./diff-parser.js").DiffParser; - var printerUtils = require("./printer-utils.js").PrinterUtils; - var utils = require("./utils.js").Utils; - - function LineByLinePrinter() { - } - - LineByLinePrinter.prototype.generateLineByLineJsonHtml = function (diffFiles, config) { - return "
\n" + - diffFiles.map(function (file) { - - var diffs; - if (file.blocks.length) diffs = generateFileHtml(file, config); - else diffs = generateEmptyDiff(); - - return "
\n" + - "
\n" + - "
\n" + - " +" + file.addedLines + "\n" + - " -" + file.deletedLines + "\n" + - "
\n" + - "
" + printerUtils.getDiffName(file) + "
\n" + - "
\n" + - "
\n" + - "
\n" + - " \n" + - " \n" + - " " + diffs + - " \n" + - "
\n" + - "
\n" + - "
\n" + - "
\n"; - }).join("\n") + - "
\n"; - }; - - function generateFileHtml(file, config) { - return file.blocks.map(function (block) { - - var lines = "\n" + - " \n" + - " " + - "
" + utils.escape(block.header) + "
" + - " \n" + - "\n"; - - var oldLines = [], newLines = []; - var processedOldLines = [], processedNewLines = []; - - for (var i = 0; i < block.lines.length; i++) { - var line = block.lines[i]; - var escapedLine = utils.escape(line.content); - - if (line.type == diffParser.LINE_TYPE.CONTEXT && !oldLines.length && !newLines.length) { - lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) { - lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); - } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) { - oldLines.push(line); - } else if (line.type == diffParser.LINE_TYPE.INSERTS && oldLines.length > newLines.length) { - newLines.push(line); - } else { - var j = 0; - var oldLine, newLine; - - if (oldLines.length === newLines.length) { - for (j = 0; j < oldLines.length; j++) { - oldLine = oldLines[j]; - newLine = newLines[j]; - - config.isCombined = file.isCombined; - var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); - - processedOldLines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, diff.first.line, diff.first.prefix); - processedNewLines += generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, diff.second.line, diff.second.prefix); - } - - lines += processedOldLines + processedNewLines; - } else { - lines += processLines(oldLines, newLines); - } - - oldLines = []; - newLines = []; - processedOldLines = []; - processedNewLines = []; - i--; - } - } - - lines += processLines(oldLines, newLines); - - return lines; - }).join("\n"); - } - - function processLines(oldLines, newLines) { - var lines = ""; - - for (j = 0; j < oldLines.length; j++) { - var oldLine = oldLines[j]; - var oldEscapedLine = utils.escape(oldLine.content); - lines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine); - } - - for (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); - } - - return lines; - } - - function generateLineHtml(type, oldNumber, newNumber, content, prefix) { - var htmlPrefix = ""; - if (prefix) htmlPrefix = "" + prefix + ""; - - var htmlContent = ""; - if (content) htmlContent = "" + content + ""; - - return "\n" + - " " + - "
" + utils.valueOrEmpty(oldNumber) + "
" + - "
" + utils.valueOrEmpty(newNumber) + "
" + - " \n" + - " " + - "
" + htmlPrefix + htmlContent + "
" + - " \n" + - "\n"; - } - - function generateEmptyDiff() { - return "\n" + - " " + - "
" + - "File without changes" + - "
" + - " \n" + - "\n"; - } - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["LineByLinePrinter"] = new LineByLinePrinter(); - -})(this); -/* - * - * HtmlPrinter (html-printer.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - var lineByLinePrinter = require("./line-by-line-printer.js").LineByLinePrinter; - var sideBySidePrinter = require("./side-by-side-printer.js").SideBySidePrinter; - - function HtmlPrinter() { - } - - HtmlPrinter.prototype.generateLineByLineJsonHtml = lineByLinePrinter.generateLineByLineJsonHtml; - - HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml; - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["HtmlPrinter"] = new HtmlPrinter(); - -})(this); -/* - * - * Diff to HTML (diff2html.js) - * Author: rtfpessoa - * - */ - -(function (ctx, undefined) { - - var diffParser = require("./diff-parser.js").DiffParser; - var htmlPrinter = require("./html-printer.js").HtmlPrinter; - - function Diff2Html() { - } - - /* - * Line diff type configuration - var config = { - "wordByWord": true, // (default) - // OR - "charByChar": true - }; - */ - - /* - * Generates pretty html from string diff input - */ - Diff2Html.prototype.getPrettyHtmlFromDiff = function (diffInput, config) { - var diffJson = diffParser.generateDiffJson(diffInput); - var configOrEmpty = config || {}; - return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); - }; - - /* - * Generates json object from string diff input - */ - Diff2Html.prototype.getJsonFromDiff = function (diffInput) { - return diffParser.generateDiffJson(diffInput); - }; - - /* - * Generates pretty html from a json object - */ - Diff2Html.prototype.getPrettyHtmlFromJson = function (diffJson, config) { - var configOrEmpty = config || {}; - return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); - }; - - /* - * Generates pretty side by side html from string diff input - */ - Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput, config) { - var diffJson = diffParser.generateDiffJson(diffInput); - - var configOrEmpty = config || {}; - return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); - }; - - /* - * Generates pretty side by side html from a json object - */ - Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function (diffJson, config) { - var configOrEmpty = config || {}; - return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); - }; - - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["Diff2Html"] = new Diff2Html(); - -})(this); +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; + +/******/ // The require function +/******/ function __webpack_require__(moduleId) { + +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; + +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; + +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); + +/******/ // Flag the module as loaded +/******/ module.loaded = true; + +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } + + +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; + +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; + +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; + +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /* WEBPACK VAR INJECTION */(function(global) {/* + * + * Diff to HTML (diff2html.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var diffParser = __webpack_require__(1).DiffParser; + var htmlPrinter = __webpack_require__(3).HtmlPrinter; + + function Diff2Html() { + } + + /* + * Line diff type configuration + var config = { + "wordByWord": true, // (default) + // OR + "charByChar": true + }; + */ + + /* + * Generates pretty html from string diff input + */ + Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { + var diffJson = diffParser.generateDiffJson(diffInput); + var configOrEmpty = config || {}; + return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); + }; + + /* + * Generates json object from string diff input + */ + Diff2Html.prototype.getJsonFromDiff = function(diffInput) { + return diffParser.generateDiffJson(diffInput); + }; + + /* + * Generates pretty html from a json object + */ + Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) { + var configOrEmpty = config || {}; + return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); + }; + + /* + * Generates pretty side by side html from string diff input + */ + Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) { + var diffJson = diffParser.generateDiffJson(diffInput); + + var configOrEmpty = config || {}; + return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); + }; + + /* + * Generates pretty side by side html from a json object + */ + Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) { + var configOrEmpty = config || {}; + return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); + }; + + var diffName = 'Diff2Html'; + var diffObject = new Diff2Html(); + module.exports[diffName] = diffObject; + // Expose diff2html in the browser + global[diffName] = diffObject; + + })(this); + + /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * + * Diff Parser (diff-parser.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var utils = __webpack_require__(2).Utils; + + var LINE_TYPE = { + INSERTS: 'd2h-ins', + DELETES: 'd2h-del', + CONTEXT: 'd2h-cntx', + INFO: 'd2h-info' + }; + + function DiffParser() { + } + + DiffParser.prototype.LINE_TYPE = LINE_TYPE; + + DiffParser.prototype.generateDiffJson = function(diffInput) { + var files = []; + var currentFile = null; + var currentBlock = null; + var oldLine = null; + var newLine = null; + + var saveBlock = function() { + /* Add previous block(if exists) before start a new file */ + if (currentBlock) { + currentFile.blocks.push(currentBlock); + currentBlock = null; + } + }; + + var saveFile = function() { + /* + * Add previous file(if exists) before start a new one + * if it has name (to avoid binary files errors) + */ + if (currentFile && currentFile.newName) { + files.push(currentFile); + currentFile = null; + } + }; + + var startFile = function() { + saveBlock(); + saveFile(); + + /* Create file structure */ + currentFile = {}; + currentFile.blocks = []; + currentFile.deletedLines = 0; + currentFile.addedLines = 0; + }; + + var startBlock = function(line) { + saveBlock(); + + var values; + + if (values = /^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line)) { + currentFile.isCombined = false; + } else if (values = /^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line)) { + currentFile.isCombined = true; + } else { + values = [0, 0]; + currentFile.isCombined = false; + } + + oldLine = values[1]; + newLine = values[2]; + + /* Create block metadata */ + currentBlock = {}; + currentBlock.lines = []; + currentBlock.oldStartLine = oldLine; + currentBlock.newStartLine = newLine; + currentBlock.header = line; + }; + + var createLine = function(line) { + var currentLine = {}; + currentLine.content = line; + + /* Fill the line data */ + if (utils.startsWith(line, '+') || utils.startsWith(line, ' +')) { + currentFile.addedLines++; + + currentLine.type = LINE_TYPE.INSERTS; + currentLine.oldNumber = null; + currentLine.newNumber = newLine++; + + currentBlock.lines.push(currentLine); + + } else if (utils.startsWith(line, '-') || utils.startsWith(line, ' -')) { + currentFile.deletedLines++; + + currentLine.type = LINE_TYPE.DELETES; + currentLine.oldNumber = oldLine++; + currentLine.newNumber = null; + + currentBlock.lines.push(currentLine); + + } else { + currentLine.type = LINE_TYPE.CONTEXT; + currentLine.oldNumber = oldLine++; + currentLine.newNumber = newLine++; + + currentBlock.lines.push(currentLine); + } + }; + + var diffLines = diffInput.split('\n'); + diffLines.forEach(function(line) { + // Unmerged paths, and possibly other non-diffable files + // https://github.com/scottgonzalez/pretty-diff/issues/11 + // Also, remove some useless lines + if (!line || utils.startsWith(line, '*')) { + return; + } + + /* Diff */ + var oldMode = /^old mode (\d{6})/; + var newMode = /^new mode (\d{6})/; + var deletedFileMode = /^deleted file mode (\d{6})/; + var newFileMode = /^new file mode (\d{6})/; + + var copyFrom = /^copy from (.+)/; + var copyTo = /^copy to (.+)/; + + var renameFrom = /^rename from (.+)/; + var renameTo = /^rename to (.+)/; + + var similarityIndex = /^similarity index (\d+)%/; + var dissimilarityIndex = /^dissimilarity index (\d+)%/; + var index = /^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/; + + /* Combined Diff */ + var combinedIndex = /^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/; + var combinedMode = /^mode (\d{6}),(\d{6})..(\d{6})/; + var combinedNewFile = /^new file mode (\d{6})/; + var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; + + var values = []; + if (utils.startsWith(line, 'diff')) { + startFile(); + } else if (currentFile && !currentFile.oldName && (values = /^--- a\/(\S+).*$/.exec(line))) { + currentFile.oldName = values[1]; + currentFile.language = getExtension(currentFile.oldName, currentFile.language); + } else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [b]?\/(\S+).*$/.exec(line))) { + currentFile.newName = values[1]; + currentFile.language = getExtension(currentFile.newName, currentFile.language); + } else if (currentFile && utils.startsWith(line, '@@')) { + startBlock(line); + } else if ((values = oldMode.exec(line))) { + currentFile.oldMode = values[1]; + } else if ((values = newMode.exec(line))) { + currentFile.newMode = values[1]; + } else if ((values = deletedFileMode.exec(line))) { + currentFile.deletedFileMode = values[1]; + } else if ((values = newFileMode.exec(line))) { + currentFile.newFileMode = values[1]; + } else if ((values = copyFrom.exec(line))) { + currentFile.oldName = values[1]; + currentFile.isCopy = true; + } else if ((values = copyTo.exec(line))) { + currentFile.newName = values[1]; + currentFile.isCopy = true; + } else if ((values = renameFrom.exec(line))) { + currentFile.oldName = values[1]; + currentFile.isRename = true; + } else if ((values = renameTo.exec(line))) { + currentFile.newName = values[1]; + currentFile.isRename = true; + } else if ((values = similarityIndex.exec(line))) { + currentFile.unchangedPercentage = values[1]; + } else if ((values = dissimilarityIndex.exec(line))) { + currentFile.changedPercentage = values[1]; + } else if ((values = index.exec(line))) { + currentFile.checksumBefore = values[1]; + currentFile.checksumAfter = values[2]; + values[2] && (currentFile.mode = values[3]); + } else if ((values = combinedIndex.exec(line))) { + currentFile.checksumBefore = [values[2], values[3]]; + currentFile.checksumAfter = values[1]; + } else if ((values = combinedMode.exec(line))) { + currentFile.oldMode = [values[2], values[3]]; + currentFile.newMode = values[1]; + } else if ((values = combinedNewFile.exec(line))) { + currentFile.newFileMode = values[1]; + } else if ((values = combinedDeletedFile.exec(line))) { + currentFile.deletedFileMode = values[1]; + } else if (currentBlock) { + createLine(line); + } + }); + + saveBlock(); + saveFile(); + + return files; + }; + + function getExtension(filename, language) { + var nameSplit = filename.split('.'); + if (nameSplit.length > 1) { + return nameSplit[nameSplit.length - 1]; + } else { + return language; + } + } + + module.exports['DiffParser'] = new DiffParser(); + + })(this); + + +/***/ }, +/* 2 */ +/***/ function(module, exports) { + + /* + * + * Utils (utils.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + function Utils() { + } + + Utils.prototype.escape = function(str) { + return str.slice(0) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/\t/g, ' '); + }; + + Utils.prototype.startsWith = function(str, start) { + return str.indexOf(start) === 0; + }; + + Utils.prototype.valueOrEmpty = function(value) { + return value ? value : ''; + }; + + module.exports['Utils'] = new Utils(); + + })(this); + + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * + * HtmlPrinter (html-printer.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var lineByLinePrinter = __webpack_require__(4).LineByLinePrinter; + var sideBySidePrinter = __webpack_require__(7).SideBySidePrinter; + + function HtmlPrinter() { + } + + HtmlPrinter.prototype.generateLineByLineJsonHtml = lineByLinePrinter.generateLineByLineJsonHtml; + + HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml; + + module.exports['HtmlPrinter'] = new HtmlPrinter(); + + })(this); + + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * + * LineByLinePrinter (line-by-line-printer.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var diffParser = __webpack_require__(1).DiffParser; + var printerUtils = __webpack_require__(5).PrinterUtils; + var utils = __webpack_require__(2).Utils; + + function LineByLinePrinter() { + } + + LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) { + return '
\n' + + diffFiles.map(function(file) { + + var diffs; + if (file.blocks.length) { + diffs = generateFileHtml(file, config); + } else { + diffs = generateEmptyDiff(); + } + + return '
\n' + + '
\n' + + '
\n' + + ' +' + file.addedLines + '\n' + + ' -' + file.deletedLines + '\n' + + '
\n' + + '
' + printerUtils.getDiffName(file) + '
\n' + + '
\n' + + '
\n' + + '
\n' + + ' \n' + + ' \n' + + ' ' + diffs + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + '
\n'; + }).join('\n') + + '
\n'; + }; + + function generateFileHtml(file, config) { + return file.blocks.map(function(block) { + + var lines = '\n' + + ' \n' + + ' ' + + '
' + utils.escape(block.header) + '
' + + ' \n' + + '\n'; + + var oldLines = []; + var newLines = []; + var processedOldLines = []; + var processedNewLines = []; + + for (var i = 0; i < block.lines.length; i++) { + var line = block.lines[i]; + var escapedLine = utils.escape(line.content); + + if (line.type == diffParser.LINE_TYPE.CONTEXT && !oldLines.length && !newLines.length) { + lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) { + lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine); + } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) { + oldLines.push(line); + } else if (line.type == diffParser.LINE_TYPE.INSERTS && oldLines.length > newLines.length) { + newLines.push(line); + } else { + var j = 0; + var oldLine, newLine; + + if (oldLines.length === newLines.length) { + for (j = 0; j < oldLines.length; j++) { + oldLine = oldLines[j]; + newLine = newLines[j]; + + config.isCombined = file.isCombined; + var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); + + processedOldLines += + generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, + diff.first.line, diff.first.prefix); + processedNewLines += + generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, + diff.second.line, diff.second.prefix); + } + + lines += processedOldLines + processedNewLines; + } else { + lines += processLines(oldLines, newLines); + } + + oldLines = []; + newLines = []; + processedOldLines = []; + processedNewLines = []; + i--; + } + } + + lines += processLines(oldLines, newLines); + + return lines; + }).join('\n'); + } + + function processLines(oldLines, newLines) { + var lines = ''; + + for (j = 0; j < oldLines.length; j++) { + var oldLine = oldLines[j]; + var oldEscapedLine = utils.escape(oldLine.content); + lines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine); + } + + for (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); + } + + return lines; + } + + function generateLineHtml(type, oldNumber, newNumber, content, prefix) { + var htmlPrefix = ''; + if (prefix) { + htmlPrefix = '' + prefix + ''; + } + + var htmlContent = ''; + if (content) { + htmlContent = '' + content + ''; + } + + return '\n' + + ' ' + + '
' + utils.valueOrEmpty(oldNumber) + '
' + + '
' + utils.valueOrEmpty(newNumber) + '
' + + ' \n' + + ' ' + + '
' + htmlPrefix + htmlContent + '
' + + ' \n' + + '\n'; + } + + function generateEmptyDiff() { + return '\n' + + ' ' + + '
' + + 'File without changes' + + '
' + + ' \n' + + '\n'; + } + + module.exports['LineByLinePrinter'] = new LineByLinePrinter(); + + })(this); + + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * + * PrinterUtils (printer-utils.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var jsDiff = __webpack_require__(6); + var utils = __webpack_require__(2).Utils; + + function PrinterUtils() { + } + + PrinterUtils.prototype.getDiffName = function(file) { + var oldFilename = file.oldName; + var newFilename = file.newName; + + 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'; + } + }; + + PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) { + var lineStart1, lineStart2; + + var prefixSize = 1; + + if (config.isCombined) { + prefixSize = 2; + } + + lineStart1 = diffLine1.substr(0, prefixSize); + lineStart2 = diffLine2.substr(0, prefixSize); + + diffLine1 = diffLine1.substr(prefixSize); + diffLine2 = diffLine2.substr(prefixSize); + + var diff; + if (config.charByChar) { + diff = jsDiff.diffChars(diffLine1, diffLine2); + } else { + diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); + } + + var highlightedLine = ''; + + diff.forEach(function(part) { + var elemType = part.added ? 'ins' : part.removed ? 'del' : null; + var escapedValue = utils.escape(part.value); + + if (elemType !== null) { + highlightedLine += '<' + elemType + '>' + escapedValue + ''; + } else { + highlightedLine += escapedValue; + } + }); + + return { + first: { + prefix: lineStart1, + line: removeIns(highlightedLine) + }, + second: { + prefix: lineStart2, + line: removeDel(highlightedLine) + } + } + }; + + function isDeletedName(name) { + return name === 'dev/null'; + } + + function removeIns(line) { + return line.replace(/(((.|\n)*?)<\/ins>)/g, ''); + } + + function removeDel(line) { + return line.replace(/(((.|\n)*?)<\/del>)/g, ''); + } + + module.exports['PrinterUtils'] = new PrinterUtils(); + + })(this); + + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* See LICENSE file for terms of use */ + + /* + * Text diff implementation. + * + * This library supports the following APIS: + * JsDiff.diffChars: Character by character diff + * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace + * JsDiff.diffLines: Line based diff + * + * JsDiff.diffCss: Diff targeted at CSS content + * + * These methods are based on the implementation proposed in + * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986). + * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 + */ + (function(global, undefined) { + var objectPrototypeToString = Object.prototype.toString; + + /*istanbul ignore next*/ + function map(arr, mapper, that) { + if (Array.prototype.map) { + return Array.prototype.map.call(arr, mapper, that); + } + + var other = new Array(arr.length); + + for (var i = 0, n = arr.length; i < n; i++) { + other[i] = mapper.call(that, arr[i], i, arr); + } + return other; + } + function clonePath(path) { + return { newPos: path.newPos, components: path.components.slice(0) }; + } + function removeEmpty(array) { + var ret = []; + for (var i = 0; i < array.length; i++) { + if (array[i]) { + ret.push(array[i]); + } + } + return ret; + } + function escapeHTML(s) { + var n = s; + n = n.replace(/&/g, '&'); + n = n.replace(//g, '>'); + n = n.replace(/"/g, '"'); + + return n; + } + + // This function handles the presence of circular references by bailing out when encountering an + // object that is already on the "stack" of items being processed. + function canonicalize(obj, stack, replacementStack) { + stack = stack || []; + replacementStack = replacementStack || []; + + var i; + + for (i = 0; i < stack.length; i += 1) { + if (stack[i] === obj) { + return replacementStack[i]; + } + } + + var canonicalizedObj; + + if ('[object Array]' === objectPrototypeToString.call(obj)) { + stack.push(obj); + canonicalizedObj = new Array(obj.length); + replacementStack.push(canonicalizedObj); + for (i = 0; i < obj.length; i += 1) { + canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack); + } + stack.pop(); + replacementStack.pop(); + } else if (typeof obj === 'object' && obj !== null) { + stack.push(obj); + canonicalizedObj = {}; + replacementStack.push(canonicalizedObj); + var sortedKeys = [], + key; + for (key in obj) { + sortedKeys.push(key); + } + sortedKeys.sort(); + for (i = 0; i < sortedKeys.length; i += 1) { + key = sortedKeys[i]; + canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack); + } + stack.pop(); + replacementStack.pop(); + } else { + canonicalizedObj = obj; + } + return canonicalizedObj; + } + + function buildValues(components, newString, oldString, useLongestToken) { + var componentPos = 0, + componentLen = components.length, + newPos = 0, + oldPos = 0; + + for (; componentPos < componentLen; componentPos++) { + var component = components[componentPos]; + if (!component.removed) { + if (!component.added && useLongestToken) { + var value = newString.slice(newPos, newPos + component.count); + value = map(value, 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; + + // Common case + if (!component.added) { + oldPos += component.count; + } + } else { + component.value = oldString.slice(oldPos, oldPos + component.count).join(''); + oldPos += component.count; + + // Reverse add and remove so removes are output first to match common convention + // The diffing algorithm is tied to add then remove output and this is the simplest + // route to get the desired output with minimal overhead. + if (componentPos && components[componentPos - 1].added) { + var tmp = components[componentPos - 1]; + components[componentPos - 1] = components[componentPos]; + components[componentPos] = tmp; + } + } + } + + return components; + } + + function Diff(ignoreWhitespace) { + this.ignoreWhitespace = ignoreWhitespace; + } + Diff.prototype = { + diff: function(oldString, newString, callback) { + var self = this; + + function done(value) { + if (callback) { + setTimeout(function() { callback(undefined, value); }, 0); + return true; + } else { + return value; + } + } + + // Handle the identity case (this is due to unrolling editLength == 0 + if (newString === oldString) { + return done([{ value: newString }]); + } + if (!newString) { + return done([{ value: oldString, removed: true }]); + } + if (!oldString) { + return done([{ value: newString, added: true }]); + } + + newString = this.tokenize(newString); + oldString = this.tokenize(oldString); + + var newLen = newString.length, oldLen = oldString.length; + var editLength = 1; + var maxEditLength = newLen + oldLen; + var bestPath = [{ newPos: -1, components: [] }]; + + // Seed editLength = 0, i.e. the content starts with the same values + var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0); + if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) { + // Identity per the equality and tokenizer + return done([{value: newString.join('')}]); + } + + // Main worker method. checks all permutations of a given edit length for acceptance. + function execEditLength() { + for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) { + var basePath; + var addPath = bestPath[diagonalPath - 1], + removePath = bestPath[diagonalPath + 1], + oldPos = (removePath ? removePath.newPos : 0) - diagonalPath; + if (addPath) { + // No one else is going to attempt to use this value, clear it + bestPath[diagonalPath - 1] = undefined; + } + + var canAdd = addPath && addPath.newPos + 1 < newLen, + canRemove = removePath && 0 <= oldPos && oldPos < oldLen; + if (!canAdd && !canRemove) { + // If this path is a terminal then prune + bestPath[diagonalPath] = undefined; + continue; + } + + // Select the diagonal that we want to branch from. We select the prior + // path whose position in the new string is the farthest from the origin + // and does not pass the bounds of the diff graph + if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) { + basePath = clonePath(removePath); + self.pushComponent(basePath.components, undefined, true); + } else { + basePath = addPath; // No need to clone, we've pulled it from the list + basePath.newPos++; + self.pushComponent(basePath.components, true, undefined); + } + + oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); + + // If we have hit the end of both strings, then we are done + if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) { + return done(buildValues(basePath.components, newString, oldString, self.useLongestToken)); + } else { + // Otherwise track this path as a potential candidate and continue. + bestPath[diagonalPath] = basePath; + } + } + + editLength++; + } + + // Performs the length of edit iteration. Is a bit fugly as this has to support the + // sync and async mode which is never fun. Loops over execEditLength until a value + // is produced. + if (callback) { + (function exec() { + setTimeout(function() { + // This should not happen, but we want to be safe. + /*istanbul ignore next */ + if (editLength > maxEditLength) { + return callback(); + } + + if (!execEditLength()) { + exec(); + } + }, 0); + }()); + } else { + while (editLength <= maxEditLength) { + var ret = execEditLength(); + if (ret) { + return ret; + } + } + } + }, + + pushComponent: function(components, added, removed) { + var last = components[components.length - 1]; + if (last && last.added === added && last.removed === removed) { + // We need to clone here as the component clone operation is just + // as shallow array clone + components[components.length - 1] = {count: last.count + 1, added: added, removed: removed }; + } else { + components.push({count: 1, added: added, removed: removed }); + } + }, + extractCommon: function(basePath, newString, oldString, diagonalPath) { + var newLen = newString.length, + oldLen = oldString.length, + newPos = basePath.newPos, + oldPos = newPos - diagonalPath, + + commonCount = 0; + while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) { + newPos++; + oldPos++; + commonCount++; + } + + if (commonCount) { + basePath.components.push({count: commonCount}); + } + + basePath.newPos = newPos; + return oldPos; + }, + + equals: function(left, right) { + var reWhitespace = /\S/; + return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)); + }, + tokenize: function(value) { + return value.split(''); + } + }; + + var CharDiff = new Diff(); + + var WordDiff = new Diff(true); + var WordWithSpaceDiff = new Diff(); + WordDiff.tokenize = WordWithSpaceDiff.tokenize = function(value) { + return removeEmpty(value.split(/(\s+|\b)/)); + }; + + var CssDiff = new Diff(true); + CssDiff.tokenize = function(value) { + return removeEmpty(value.split(/([{}:;,]|\s+)/)); + }; + + var LineDiff = new Diff(); + + var TrimmedLineDiff = new Diff(); + TrimmedLineDiff.ignoreTrim = true; + + LineDiff.tokenize = TrimmedLineDiff.tokenize = function(value) { + var retLines = [], + lines = value.split(/^/m); + for (var i = 0; i < lines.length; i++) { + var line = lines[i], + lastLine = lines[i - 1], + lastLineLastChar = lastLine && lastLine[lastLine.length - 1]; + + // Merge lines that may contain windows new lines + if (line === '\n' && lastLineLastChar === '\r') { + retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n'; + } else { + if (this.ignoreTrim) { + line = line.trim(); + // add a newline unless this is the last line. + if (i < lines.length - 1) { + line += '\n'; + } + } + retLines.push(line); + } + } + + return retLines; + }; + + var PatchDiff = new Diff(); + PatchDiff.tokenize = function(value) { + var ret = [], + linesAndNewlines = value.split(/(\n|\r\n)/); + + // Ignore the final empty token that occurs if the string ends with a new line + if (!linesAndNewlines[linesAndNewlines.length - 1]) { + linesAndNewlines.pop(); + } + + // Merge the content and line separators into single tokens + for (var i = 0; i < linesAndNewlines.length; i++) { + var line = linesAndNewlines[i]; + + if (i % 2) { + ret[ret.length - 1] += line; + } else { + ret.push(line); + } + } + return ret; + }; + + var SentenceDiff = new Diff(); + SentenceDiff.tokenize = function(value) { + return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/)); + }; + + var JsonDiff = new Diff(); + // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a + // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output: + JsonDiff.useLongestToken = true; + JsonDiff.tokenize = LineDiff.tokenize; + JsonDiff.equals = function(left, right) { + return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1')); + }; + + var JsDiff = { + Diff: Diff, + + diffChars: function(oldStr, newStr, callback) { return CharDiff.diff(oldStr, newStr, callback); }, + diffWords: function(oldStr, newStr, callback) { return WordDiff.diff(oldStr, newStr, callback); }, + diffWordsWithSpace: function(oldStr, newStr, callback) { return WordWithSpaceDiff.diff(oldStr, newStr, callback); }, + diffLines: function(oldStr, newStr, callback) { return LineDiff.diff(oldStr, newStr, callback); }, + diffTrimmedLines: function(oldStr, newStr, callback) { return TrimmedLineDiff.diff(oldStr, newStr, callback); }, + + diffSentences: function(oldStr, newStr, callback) { return SentenceDiff.diff(oldStr, newStr, callback); }, + + diffCss: function(oldStr, newStr, callback) { return CssDiff.diff(oldStr, newStr, callback); }, + diffJson: function(oldObj, newObj, callback) { + return JsonDiff.diff( + typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '), + typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '), + callback + ); + }, + + createTwoFilesPatch: function(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) { + var ret = []; + + if (oldFileName == newFileName) { + ret.push('Index: ' + oldFileName); + } + ret.push('==================================================================='); + ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader)); + ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader)); + + var diff = PatchDiff.diff(oldStr, newStr); + diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier + + // Formats a given set of lines for printing as context lines in a patch + function contextLines(lines) { + return map(lines, function(entry) { return ' ' + entry; }); + } + + // Outputs the no newline at end of file warning if needed + function eofNL(curRange, i, current) { + var last = diff[diff.length - 2], + isLast = i === diff.length - 2, + isLastOfType = i === diff.length - 3 && current.added !== last.added; + + // Figure out if this is the last line for the given file and missing NL + if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) { + curRange.push('\\ No newline at end of file'); + } + } + + var oldRangeStart = 0, newRangeStart = 0, curRange = [], + oldLine = 1, newLine = 1; + for (var i = 0; i < diff.length; i++) { + var current = diff[i], + lines = current.lines || current.value.replace(/\n$/, '').split('\n'); + current.lines = lines; + + if (current.added || current.removed) { + // If we have previous context, start with that + if (!oldRangeStart) { + var prev = diff[i - 1]; + oldRangeStart = oldLine; + newRangeStart = newLine; + + if (prev) { + curRange = contextLines(prev.lines.slice(-4)); + oldRangeStart -= curRange.length; + newRangeStart -= curRange.length; + } + } + + // Output our changes + curRange.push.apply(curRange, map(lines, function(entry) { + return (current.added ? '+' : '-') + entry; + })); + eofNL(curRange, i, current); + + // Track the updated file position + if (current.added) { + newLine += lines.length; + } else { + oldLine += lines.length; + } + } else { + // Identical context lines. Track line changes + if (oldRangeStart) { + // Close out any changes that have been output (or join overlapping) + if (lines.length <= 8 && i < diff.length - 2) { + // Overlapping + curRange.push.apply(curRange, contextLines(lines)); + } else { + // end the range and output + var contextSize = Math.min(lines.length, 4); + ret.push( + '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize) + + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize) + + ' @@'); + ret.push.apply(ret, curRange); + ret.push.apply(ret, contextLines(lines.slice(0, contextSize))); + if (lines.length <= 4) { + eofNL(ret, i, current); + } + + oldRangeStart = 0; + newRangeStart = 0; + curRange = []; + } + } + oldLine += lines.length; + newLine += lines.length; + } + } + + return ret.join('\n') + '\n'; + }, + + createPatch: function(fileName, oldStr, newStr, oldHeader, newHeader) { + return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader); + }, + + applyPatch: function(oldStr, uniDiff) { + var diffstr = uniDiff.split('\n'), + hunks = [], + i = 0, + remEOFNL = false, + addEOFNL = false; + + // Skip to the first change hunk + while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) { + i++; + } + + // Parse the unified diff + for (; i < diffstr.length; i++) { + if (diffstr[i][0] === '@') { + var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/); + hunks.unshift({ + start: chnukHeader[3], + oldlength: +chnukHeader[2], + removed: [], + newlength: chnukHeader[4], + added: [] + }); + } else if (diffstr[i][0] === '+') { + hunks[0].added.push(diffstr[i].substr(1)); + } else if (diffstr[i][0] === '-') { + hunks[0].removed.push(diffstr[i].substr(1)); + } else if (diffstr[i][0] === ' ') { + hunks[0].added.push(diffstr[i].substr(1)); + hunks[0].removed.push(diffstr[i].substr(1)); + } else if (diffstr[i][0] === '\\') { + if (diffstr[i - 1][0] === '+') { + remEOFNL = true; + } else if (diffstr[i - 1][0] === '-') { + addEOFNL = true; + } + } + } + + // Apply the diff to the input + var lines = oldStr.split('\n'); + for (i = hunks.length - 1; i >= 0; i--) { + var hunk = hunks[i]; + // Sanity check the input string. Bail if we don't match. + for (var j = 0; j < hunk.oldlength; j++) { + if (lines[hunk.start - 1 + j] !== hunk.removed[j]) { + return false; + } + } + Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added)); + } + + // Handle EOFNL insertion/removal + if (remEOFNL) { + while (!lines[lines.length - 1]) { + lines.pop(); + } + } else if (addEOFNL) { + lines.push(''); + } + return lines.join('\n'); + }, + + convertChangesToXML: function(changes) { + var ret = []; + for (var i = 0; i < changes.length; i++) { + var change = changes[i]; + if (change.added) { + ret.push(''); + } else if (change.removed) { + ret.push(''); + } + + ret.push(escapeHTML(change.value)); + + if (change.added) { + ret.push(''); + } else if (change.removed) { + ret.push(''); + } + } + return ret.join(''); + }, + + // See: http://code.google.com/p/google-diff-match-patch/wiki/API + convertChangesToDMP: function(changes) { + var ret = [], + change, + operation; + for (var i = 0; i < changes.length; i++) { + change = changes[i]; + if (change.added) { + operation = 1; + } else if (change.removed) { + operation = -1; + } else { + operation = 0; + } + + ret.push([operation, change.value]); + } + return ret; + }, + + canonicalize: canonicalize + }; + + /*istanbul ignore next */ + /*global module */ + if (typeof module !== 'undefined' && module.exports) { + module.exports = JsDiff; + } else if (true) { + /*global define */ + !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() { return JsDiff; }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); + } else if (typeof global.JsDiff === 'undefined') { + global.JsDiff = JsDiff; + } + }(this)); + + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + /* + * + * HtmlPrinter (html-printer.js) + * Author: rtfpessoa + * + */ + + (function(ctx, undefined) { + + var diffParser = __webpack_require__(1).DiffParser; + var printerUtils = __webpack_require__(5).PrinterUtils; + var utils = __webpack_require__(2).Utils; + + function SideBySidePrinter() { + } + + SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) { + return '
\n' + + diffFiles.map(function(file) { + + var diffs; + if (file.blocks.length) { + diffs = generateSideBySideFileHtml(file, config); + } else { + diffs = generateEmptyDiff(); + } + + return '
\n' + + '
\n' + + '
\n' + + ' +' + file.addedLines + '\n' + + ' -' + file.deletedLines + '\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'; + }; + + function generateSideBySideFileHtml(file, config) { + var fileHtml = {}; + fileHtml.left = ''; + fileHtml.right = ''; + + file.blocks.forEach(function(block) { + + fileHtml.left += '\n' + + ' \n' + + ' ' + + '
' + + ' ' + utils.escape(block.header) + + '
' + + ' \n' + + '\n'; + + fileHtml.right += '\n' + + ' \n' + + ' ' + + '
' + + ' \n' + + '\n'; + + var oldLines = []; + var newLines = []; + var tmpHtml = ''; + + for (var i = 0; i < block.lines.length; i++) { + var line = block.lines[i]; + var escapedLine = utils.escape(line.content); + + if (line.type == diffParser.LINE_TYPE.CONTEXT && !oldLines.length && !newLines.length) { + fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine); + fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); + } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) { + fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); + fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); + } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) { + oldLines.push(line); + } else if (line.type == diffParser.LINE_TYPE.INSERTS && oldLines.length > newLines.length) { + newLines.push(line); + } else { + var j = 0; + var oldLine, newLine; + + if (oldLines.length === newLines.length) { + for (j = 0; j < oldLines.length; j++) { + oldLine = oldLines[j]; + newLine = newLines[j]; + + config.isCombined = file.isCombined; + + var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); + + fileHtml.left += + generateSingleLineHtml(oldLine.type, oldLine.oldNumber, + diff.first.line, diff.first.prefix); + fileHtml.right += + generateSingleLineHtml(newLine.type, newLine.newNumber, + diff.second.line, diff.second.prefix); + } + } else { + tmpHtml = processLines(oldLines, newLines); + fileHtml.left += tmpHtml.left; + fileHtml.right += tmpHtml.right; + } + + oldLines = []; + newLines = []; + i--; + } + } + + tmpHtml = processLines(oldLines, newLines); + fileHtml.left += tmpHtml.left; + fileHtml.right += tmpHtml.right; + }); + + return fileHtml; + } + + function processLines(oldLines, newLines) { + var fileHtml = {}; + fileHtml.left = ''; + fileHtml.right = ''; + + var maxLinesNumber = Math.max(oldLines.length, newLines.length); + for (j = 0; j < maxLinesNumber; j++) { + var oldLine = oldLines[j]; + var newLine = newLines[j]; + + if (oldLine && newLine) { + fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content)); + fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); + } else if (oldLine) { + fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content)); + fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); + } else if (newLine) { + fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); + fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); + } else { + console.error('How did it get here?'); + } + } + + return fileHtml; + } + + function generateSingleLineHtml(type, number, content, prefix) { + var htmlPrefix = ''; + if (prefix) { + htmlPrefix = '' + prefix + ''; + } + + var htmlContent = ''; + if (content) { + htmlContent = '' + content + ''; + } + + return '\n' + + ' ' + number + '\n' + + ' ' + + '
' + htmlPrefix + htmlContent + '
' + + ' \n' + + ' \n'; + } + + function generateEmptyDiff() { + var fileHtml = {}; + fileHtml.right = ''; + + fileHtml.left = '\n' + + ' ' + + '
' + + 'File without changes' + + '
' + + ' \n' + + '\n'; + + return fileHtml; + } + + module.exports['SideBySidePrinter'] = new SideBySidePrinter(); + + })(this); + + +/***/ } +/******/ ]); \ No newline at end of file diff --git a/dist/diff2html.min.js b/dist/diff2html.min.js index 61c296a..030a279 100644 --- a/dist/diff2html.min.js +++ b/dist/diff2html.min.js @@ -1 +1 @@ -function require(){return $globalHolder}var $globalHolder="undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof this&&this||Function("return this")();!function(global,undefined){function map(arr,mapper,that){if(Array.prototype.map)return Array.prototype.map.call(arr,mapper,that);for(var other=new Array(arr.length),i=0,n=arr.length;n>i;i++)other[i]=mapper.call(that,arr[i],i,arr);return other}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}function removeEmpty(array){for(var ret=[],i=0;i/g,">"),n=n.replace(/"/g,""")}function canonicalize(obj,stack,replacementStack){stack=stack||[],replacementStack=replacementStack||[];var i;for(i=0;icomponentPos;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=map(value,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)}}return components}function Diff(ignoreWhitespace){this.ignoreWhitespace=ignoreWhitespace}var objectPrototypeToString=Object.prototype.toString;Diff.prototype={diff:function(oldString,newString,callback){function done(value){return callback?(setTimeout(function(){callback(undefined,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1],oldPos=(removePath?removePath.newPos:0)-diagonalPath;addPath&&(bestPath[diagonalPath-1]=undefined);var canAdd=addPath&&addPath.newPos+1=0&&oldLen>oldPos;if(canAdd||canRemove){if(!canAdd||canRemove&&addPath.newPos=newLen&&oldPos+1>=oldLen)return done(buildValues(basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=undefined}editLength++}var self=this;if(newString===oldString)return done([{value:newString}]);if(!newString)return done([{value:oldString,removed:!0}]);if(!oldString)return done([{value:newString,added:!0}]);newString=this.tokenize(newString),oldString=this.tokenize(oldString);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("")}]);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){var reWhitespace=/\S/;return left===right||this.ignoreWhitespace&&!reWhitespace.test(left)&&!reWhitespace.test(right)},tokenize:function(value){return value.split("")}};var CharDiff=new Diff,WordDiff=new Diff(!0),WordWithSpaceDiff=new Diff;WordDiff.tokenize=WordWithSpaceDiff.tokenize=function(value){return removeEmpty(value.split(/(\s+|\b)/))};var CssDiff=new Diff(!0);CssDiff.tokenize=function(value){return removeEmpty(value.split(/([{}:;,]|\s+)/))};var LineDiff=new Diff,TrimmedLineDiff=new Diff;TrimmedLineDiff.ignoreTrim=!0,LineDiff.tokenize=TrimmedLineDiff.tokenize=function(value){for(var retLines=[],lines=value.split(/^/m),i=0;i=0;i--){for(var hunk=hunks[i],j=0;j"):change.removed&&ret.push(""),ret.push(escapeHTML(change.value)),change.added?ret.push("
"):change.removed&&ret.push("
")}return ret.join("")},convertChangesToDMP:function(changes){for(var change,operation,ret=[],i=0;i/g,">").replace(/\t/g," ")},Utils.prototype.startsWith=function(str,start){return 0===str.indexOf(start)},Utils.prototype.valueOrEmpty=function(value){return value?value:""},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).Utils=new Utils}(this),function(ctx,undefined){function DiffParser(){}function getExtension(filename,language){var nameSplit=filename.split(".");return nameSplit.length>1?nameSplit[nameSplit.length-1]:language}var utils=require("./utils.js").Utils,LINE_TYPE={INSERTS:"d2h-ins",DELETES:"d2h-del",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,utils.startsWith(line,"+")||utils.startsWith(line," +")?(currentFile.addedLines++,currentLine.type=LINE_TYPE.INSERTS,currentLine.oldNumber=null,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine)):utils.startsWith(line,"-")||utils.startsWith(line," -")?(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");return diffLines.forEach(function(line){if(line&&!utils.startsWith(line,"*")){var 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})/,values=[];utils.startsWith(line,"diff")?startFile():currentFile&&!currentFile.oldName&&(values=/^--- a\/(\S+).*$/.exec(line))?(currentFile.oldName=values[1],currentFile.language=getExtension(currentFile.oldName,currentFile.language)):currentFile&&!currentFile.newName&&(values=/^\+\+\+ [b]?\/(\S+).*$/.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},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).DiffParser=new DiffParser}(this),function(ctx,undefined){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="undefined"!=typeof JsDiff&&JsDiff||require("diff"),utils=require("./utils.js").Utils;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="";return diff.forEach(function(part){var elemType=part.added?"ins":part.removed?"del":null,escapedValue=utils.escape(part.value);highlightedLine+=null!==elemType?"<"+elemType+">"+escapedValue+"":escapedValue}),{first:{prefix:lineStart1,line:removeIns(highlightedLine)},second:{prefix:lineStart2,line:removeDel(highlightedLine)}}},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).PrinterUtils=new PrinterUtils}(this),function(ctx,undefined){function SideBySidePrinter(){}function generateSideBySideFileHtml(file,config){var fileHtml={};return fileHtml.left="",fileHtml.right="",file.blocks.forEach(function(block){fileHtml.left+='\n \n
'+utils.escape(block.header)+"
\n\n",fileHtml.right+='\n \n
\n\n';for(var oldLines=[],newLines=[],tmpHtml="",i=0;inewLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(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=require("./diff-parser.js").DiffParser,printerUtils=require("./printer-utils.js").PrinterUtils,utils=require("./utils.js").Utils;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 -'+file.deletedLines+'\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"},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).SideBySidePrinter=new SideBySidePrinter}(this),function(ctx,undefined){function LineByLinePrinter(){}function generateFileHtml(file,config){return file.blocks.map(function(block){for(var lines='\n \n
'+utils.escape(block.header)+"
\n\n",oldLines=[],newLines=[],processedOldLines=[],processedNewLines=[],i=0;inewLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(oldLines.length===newLines.length){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=require("./diff-parser.js").DiffParser,printerUtils=require("./printer-utils.js").PrinterUtils,utils=require("./utils.js").Utils;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 -'+file.deletedLines+'\n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n \n \n '+diffs+" \n
\n
\n
\n
\n"}).join("\n")+"
\n"},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).LineByLinePrinter=new LineByLinePrinter}(this),function(ctx,undefined){function HtmlPrinter(){}var lineByLinePrinter=require("./line-by-line-printer.js").LineByLinePrinter,sideBySidePrinter=require("./side-by-side-printer.js").SideBySidePrinter;HtmlPrinter.prototype.generateLineByLineJsonHtml=lineByLinePrinter.generateLineByLineJsonHtml,HtmlPrinter.prototype.generateSideBySideJsonHtml=sideBySidePrinter.generateSideBySideJsonHtml,("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).HtmlPrinter=new HtmlPrinter}(this),function(ctx,undefined){function Diff2Html(){}var diffParser=require("./diff-parser.js").DiffParser,htmlPrinter=require("./html-printer.js").HtmlPrinter;Diff2Html.prototype.getPrettyHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getJsonFromDiff=function(diffInput){return diffParser.generateDiffJson(diffInput)},Diff2Html.prototype.getPrettyHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty)},("undefined"!=typeof module&&module.exports||"undefined"!=typeof exports&&exports||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||"undefined"!=typeof $this&&$this||Function("return this")()).Diff2Html=new Diff2Html}(this); \ No newline at end of file +!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,htmlPrinter=__webpack_require__(3).HtmlPrinter;Diff2Html.prototype.getPrettyHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getJsonFromDiff=function(diffInput){return diffParser.generateDiffJson(diffInput)},Diff2Html.prototype.getPrettyHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(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",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,utils.startsWith(line,"+")||utils.startsWith(line," +")?(currentFile.addedLines++,currentLine.type=LINE_TYPE.INSERTS,currentLine.oldNumber=null,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine)):utils.startsWith(line,"-")||utils.startsWith(line," -")?(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");return diffLines.forEach(function(line){if(line&&!utils.startsWith(line,"*")){var 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})/,values=[];utils.startsWith(line,"diff")?startFile():currentFile&&!currentFile.oldName&&(values=/^--- a\/(\S+).*$/.exec(line))?(currentFile.oldName=values[1],currentFile.language=getExtension(currentFile.oldName,currentFile.language)):currentFile&&!currentFile.newName&&(values=/^\+\+\+ [b]?\/(\S+).*$/.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.startsWith=function(str,start){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 HtmlPrinter(){}var lineByLinePrinter=__webpack_require__(4).LineByLinePrinter,sideBySidePrinter=__webpack_require__(7).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){for(var lines='\n \n
'+utils.escape(block.header)+"
\n\n",oldLines=[],newLines=[],processedOldLines=[],processedNewLines=[],i=0;inewLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(oldLines.length===newLines.length){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__(5).PrinterUtils,utils=__webpack_require__(2).Utils;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 -'+file.deletedLines+'\n
\n
'+printerUtils.getDiffName(file)+'
\n
\n
\n
\n \n \n '+diffs+" \n
\n
\n
\n
\n"}).join("\n")+"
\n"},module.exports.LineByLinePrinter=new LineByLinePrinter}(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__(6),utils=__webpack_require__(2).Utils;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="";return diff.forEach(function(part){var elemType=part.added?"ins":part.removed?"del":null,escapedValue=utils.escape(part.value);highlightedLine+=null!==elemType?"<"+elemType+">"+escapedValue+"":escapedValue}),{first:{prefix:lineStart1,line:removeIns(highlightedLine)},second:{prefix:lineStart2,line:removeDel(highlightedLine)}}},module.exports.PrinterUtils=new PrinterUtils}(this)},function(module,exports){var __WEBPACK_AMD_DEFINE_ARRAY__,__WEBPACK_AMD_DEFINE_RESULT__;!function(global,undefined){function map(arr,mapper,that){if(Array.prototype.map)return Array.prototype.map.call(arr,mapper,that);for(var other=new Array(arr.length),i=0,n=arr.length;n>i;i++)other[i]=mapper.call(that,arr[i],i,arr);return other}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}function removeEmpty(array){for(var ret=[],i=0;i/g,">"),n=n.replace(/"/g,""")}function canonicalize(obj,stack,replacementStack){stack=stack||[],replacementStack=replacementStack||[];var i;for(i=0;icomponentPos;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=map(value,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)}}return components}function Diff(ignoreWhitespace){this.ignoreWhitespace=ignoreWhitespace}var objectPrototypeToString=Object.prototype.toString;Diff.prototype={diff:function(oldString,newString,callback){function done(value){return callback?(setTimeout(function(){callback(undefined,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1],oldPos=(removePath?removePath.newPos:0)-diagonalPath;addPath&&(bestPath[diagonalPath-1]=undefined);var canAdd=addPath&&addPath.newPos+1=0&&oldLen>oldPos;if(canAdd||canRemove){if(!canAdd||canRemove&&addPath.newPos=newLen&&oldPos+1>=oldLen)return done(buildValues(basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=undefined}editLength++}var self=this;if(newString===oldString)return done([{value:newString}]);if(!newString)return done([{value:oldString,removed:!0}]);if(!oldString)return done([{value:newString,added:!0}]);newString=this.tokenize(newString),oldString=this.tokenize(oldString);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("")}]);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){var reWhitespace=/\S/;return left===right||this.ignoreWhitespace&&!reWhitespace.test(left)&&!reWhitespace.test(right)},tokenize:function(value){return value.split("")}};var CharDiff=new Diff,WordDiff=new Diff(!0),WordWithSpaceDiff=new Diff;WordDiff.tokenize=WordWithSpaceDiff.tokenize=function(value){return removeEmpty(value.split(/(\s+|\b)/))};var CssDiff=new Diff(!0);CssDiff.tokenize=function(value){return removeEmpty(value.split(/([{}:;,]|\s+)/))};var LineDiff=new Diff,TrimmedLineDiff=new Diff;TrimmedLineDiff.ignoreTrim=!0,LineDiff.tokenize=TrimmedLineDiff.tokenize=function(value){for(var retLines=[],lines=value.split(/^/m),i=0;i=0;i--){for(var hunk=hunks[i],j=0;j"):change.removed&&ret.push(""),ret.push(escapeHTML(change.value)),change.added?ret.push(""):change.removed&&ret.push("
")}return ret.join("")},convertChangesToDMP:function(changes){for(var change,operation,ret=[],i=0;i\n
'+utils.escape(block.header)+"
\n\n",fileHtml.right+='\n \n
\n\n';for(var oldLines=[],newLines=[],tmpHtml="",i=0;inewLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(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__(5).PrinterUtils,utils=__webpack_require__(2).Utils;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 -'+file.deletedLines+'\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"},module.exports.SideBySidePrinter=new SideBySidePrinter}(this)}]); \ No newline at end of file diff --git a/lib/diff.js b/lib/diff.js deleted file mode 100644 index 292caf2..0000000 --- a/lib/diff.js +++ /dev/null @@ -1,643 +0,0 @@ -/* See LICENSE file for terms of use */ - -/* - * Text diff implementation. - * - * This library supports the following APIS: - * JsDiff.diffChars: Character by character diff - * JsDiff.diffWords: Word (as defined by \b regex) diff which ignores whitespace - * JsDiff.diffLines: Line based diff - * - * JsDiff.diffCss: Diff targeted at CSS content - * - * These methods are based on the implementation proposed in - * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986). - * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927 - */ -(function (global, undefined) { - var objectPrototypeToString = Object.prototype.toString; - - /*istanbul ignore next*/ - function map(arr, mapper, that) { - if (Array.prototype.map) { - return Array.prototype.map.call(arr, mapper, that); - } - - var other = new Array(arr.length); - - for (var i = 0, n = arr.length; i < n; i++) { - other[i] = mapper.call(that, arr[i], i, arr); - } - return other; - } - - function clonePath(path) { - return {newPos: path.newPos, components: path.components.slice(0)}; - } - - function removeEmpty(array) { - var ret = []; - for (var i = 0; i < array.length; i++) { - if (array[i]) { - ret.push(array[i]); - } - } - return ret; - } - - function escapeHTML(s) { - var n = s; - n = n.replace(/&/g, '&'); - n = n.replace(//g, '>'); - n = n.replace(/"/g, '"'); - - return n; - } - - // This function handles the presence of circular references by bailing out when encountering an - // object that is already on the "stack" of items being processed. - function canonicalize(obj, stack, replacementStack) { - stack = stack || []; - replacementStack = replacementStack || []; - - var i; - - for (i = 0; i < stack.length; i += 1) { - if (stack[i] === obj) { - return replacementStack[i]; - } - } - - var canonicalizedObj; - - if ('[object Array]' === objectPrototypeToString.call(obj)) { - stack.push(obj); - canonicalizedObj = new Array(obj.length); - replacementStack.push(canonicalizedObj); - for (i = 0; i < obj.length; i += 1) { - canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack); - } - stack.pop(); - replacementStack.pop(); - } else if (typeof obj === 'object' && obj !== null) { - stack.push(obj); - canonicalizedObj = {}; - replacementStack.push(canonicalizedObj); - var sortedKeys = [], - key; - for (key in obj) { - sortedKeys.push(key); - } - sortedKeys.sort(); - for (i = 0; i < sortedKeys.length; i += 1) { - key = sortedKeys[i]; - canonicalizedObj[key] = canonicalize(obj[key], stack, replacementStack); - } - stack.pop(); - replacementStack.pop(); - } else { - canonicalizedObj = obj; - } - return canonicalizedObj; - } - - function buildValues(components, newString, oldString, useLongestToken) { - var componentPos = 0, - componentLen = components.length, - newPos = 0, - oldPos = 0; - - for (; componentPos < componentLen; componentPos++) { - var component = components[componentPos]; - if (!component.removed) { - if (!component.added && useLongestToken) { - var value = newString.slice(newPos, newPos + component.count); - value = map(value, 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; - - // Common case - if (!component.added) { - oldPos += component.count; - } - } else { - component.value = oldString.slice(oldPos, oldPos + component.count).join(''); - oldPos += component.count; - - // Reverse add and remove so removes are output first to match common convention - // The diffing algorithm is tied to add then remove output and this is the simplest - // route to get the desired output with minimal overhead. - if (componentPos && components[componentPos - 1].added) { - var tmp = components[componentPos - 1]; - components[componentPos - 1] = components[componentPos]; - components[componentPos] = tmp; - } - } - } - - return components; - } - - function Diff(ignoreWhitespace) { - this.ignoreWhitespace = ignoreWhitespace; - } - - Diff.prototype = { - diff: function (oldString, newString, callback) { - var self = this; - - function done(value) { - if (callback) { - setTimeout(function () { - callback(undefined, value); - }, 0); - return true; - } else { - return value; - } - } - - // Handle the identity case (this is due to unrolling editLength == 0 - if (newString === oldString) { - return done([{value: newString}]); - } - if (!newString) { - return done([{value: oldString, removed: true}]); - } - if (!oldString) { - return done([{value: newString, added: true}]); - } - - newString = this.tokenize(newString); - oldString = this.tokenize(oldString); - - var newLen = newString.length, oldLen = oldString.length; - var editLength = 1; - var maxEditLength = newLen + oldLen; - var bestPath = [{newPos: -1, components: []}]; - - // Seed editLength = 0, i.e. the content starts with the same values - var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0); - if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) { - // Identity per the equality and tokenizer - return done([{value: newString.join('')}]); - } - - // Main worker method. checks all permutations of a given edit length for acceptance. - function execEditLength() { - for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) { - var basePath; - var addPath = bestPath[diagonalPath - 1], - removePath = bestPath[diagonalPath + 1], - oldPos = (removePath ? removePath.newPos : 0) - diagonalPath; - if (addPath) { - // No one else is going to attempt to use this value, clear it - bestPath[diagonalPath - 1] = undefined; - } - - var canAdd = addPath && addPath.newPos + 1 < newLen, - canRemove = removePath && 0 <= oldPos && oldPos < oldLen; - if (!canAdd && !canRemove) { - // If this path is a terminal then prune - bestPath[diagonalPath] = undefined; - continue; - } - - // Select the diagonal that we want to branch from. We select the prior - // path whose position in the new string is the farthest from the origin - // and does not pass the bounds of the diff graph - if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) { - basePath = clonePath(removePath); - self.pushComponent(basePath.components, undefined, true); - } else { - basePath = addPath; // No need to clone, we've pulled it from the list - basePath.newPos++; - self.pushComponent(basePath.components, true, undefined); - } - - oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); - - // If we have hit the end of both strings, then we are done - if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) { - return done(buildValues(basePath.components, newString, oldString, self.useLongestToken)); - } else { - // Otherwise track this path as a potential candidate and continue. - bestPath[diagonalPath] = basePath; - } - } - - editLength++; - } - - // Performs the length of edit iteration. Is a bit fugly as this has to support the - // sync and async mode which is never fun. Loops over execEditLength until a value - // is produced. - if (callback) { - (function exec() { - setTimeout(function () { - // This should not happen, but we want to be safe. - /*istanbul ignore next */ - if (editLength > maxEditLength) { - return callback(); - } - - if (!execEditLength()) { - exec(); - } - }, 0); - }()); - } else { - while (editLength <= maxEditLength) { - var ret = execEditLength(); - if (ret) { - return ret; - } - } - } - }, - - pushComponent: function (components, added, removed) { - var last = components[components.length - 1]; - if (last && last.added === added && last.removed === removed) { - // We need to clone here as the component clone operation is just - // as shallow array clone - components[components.length - 1] = {count: last.count + 1, added: added, removed: removed}; - } else { - components.push({count: 1, added: added, removed: removed}); - } - }, - extractCommon: function (basePath, newString, oldString, diagonalPath) { - var newLen = newString.length, - oldLen = oldString.length, - newPos = basePath.newPos, - oldPos = newPos - diagonalPath, - - commonCount = 0; - while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) { - newPos++; - oldPos++; - commonCount++; - } - - if (commonCount) { - basePath.components.push({count: commonCount}); - } - - basePath.newPos = newPos; - return oldPos; - }, - - equals: function (left, right) { - var reWhitespace = /\S/; - return left === right || (this.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right)); - }, - tokenize: function (value) { - return value.split(''); - } - }; - - var CharDiff = new Diff(); - - var WordDiff = new Diff(true); - var WordWithSpaceDiff = new Diff(); - WordDiff.tokenize = WordWithSpaceDiff.tokenize = function (value) { - return removeEmpty(value.split(/(\s+|\b)/)); - }; - - var CssDiff = new Diff(true); - CssDiff.tokenize = function (value) { - return removeEmpty(value.split(/([{}:;,]|\s+)/)); - }; - - var LineDiff = new Diff(); - - var TrimmedLineDiff = new Diff(); - TrimmedLineDiff.ignoreTrim = true; - - LineDiff.tokenize = TrimmedLineDiff.tokenize = function (value) { - var retLines = [], - lines = value.split(/^/m); - for (var i = 0; i < lines.length; i++) { - var line = lines[i], - lastLine = lines[i - 1], - lastLineLastChar = lastLine && lastLine[lastLine.length - 1]; - - // Merge lines that may contain windows new lines - if (line === '\n' && lastLineLastChar === '\r') { - retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0, -1) + '\r\n'; - } else { - if (this.ignoreTrim) { - line = line.trim(); - // add a newline unless this is the last line. - if (i < lines.length - 1) { - line += '\n'; - } - } - retLines.push(line); - } - } - - return retLines; - }; - - var PatchDiff = new Diff(); - PatchDiff.tokenize = function (value) { - var ret = [], - linesAndNewlines = value.split(/(\n|\r\n)/); - - // Ignore the final empty token that occurs if the string ends with a new line - if (!linesAndNewlines[linesAndNewlines.length - 1]) { - linesAndNewlines.pop(); - } - - // Merge the content and line separators into single tokens - for (var i = 0; i < linesAndNewlines.length; i++) { - var line = linesAndNewlines[i]; - - if (i % 2) { - ret[ret.length - 1] += line; - } else { - ret.push(line); - } - } - return ret; - }; - - var SentenceDiff = new Diff(); - SentenceDiff.tokenize = function (value) { - return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/)); - }; - - var JsonDiff = new Diff(); - // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a - // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output: - JsonDiff.useLongestToken = true; - JsonDiff.tokenize = LineDiff.tokenize; - JsonDiff.equals = function (left, right) { - return LineDiff.equals(left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1')); - }; - - var JsDiff = { - Diff: Diff, - - diffChars: function (oldStr, newStr, callback) { - return CharDiff.diff(oldStr, newStr, callback); - }, - diffWords: function (oldStr, newStr, callback) { - return WordDiff.diff(oldStr, newStr, callback); - }, - diffWordsWithSpace: function (oldStr, newStr, callback) { - return WordWithSpaceDiff.diff(oldStr, newStr, callback); - }, - diffLines: function (oldStr, newStr, callback) { - return LineDiff.diff(oldStr, newStr, callback); - }, - diffTrimmedLines: function (oldStr, newStr, callback) { - return TrimmedLineDiff.diff(oldStr, newStr, callback); - }, - - diffSentences: function (oldStr, newStr, callback) { - return SentenceDiff.diff(oldStr, newStr, callback); - }, - - diffCss: function (oldStr, newStr, callback) { - return CssDiff.diff(oldStr, newStr, callback); - }, - diffJson: function (oldObj, newObj, callback) { - return JsonDiff.diff( - typeof oldObj === 'string' ? oldObj : JSON.stringify(canonicalize(oldObj), undefined, ' '), - typeof newObj === 'string' ? newObj : JSON.stringify(canonicalize(newObj), undefined, ' '), - callback - ); - }, - - createTwoFilesPatch: function (oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader) { - var ret = []; - - if (oldFileName == newFileName) { - ret.push('Index: ' + oldFileName); - } - ret.push('==================================================================='); - ret.push('--- ' + oldFileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader)); - ret.push('+++ ' + newFileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader)); - - var diff = PatchDiff.diff(oldStr, newStr); - diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier - - // Formats a given set of lines for printing as context lines in a patch - function contextLines(lines) { - return map(lines, function (entry) { - return ' ' + entry; - }); - } - - // Outputs the no newline at end of file warning if needed - function eofNL(curRange, i, current) { - var last = diff[diff.length - 2], - isLast = i === diff.length - 2, - isLastOfType = i === diff.length - 3 && current.added !== last.added; - - // Figure out if this is the last line for the given file and missing NL - if (!(/\n$/.test(current.value)) && (isLast || isLastOfType)) { - curRange.push('\\ No newline at end of file'); - } - } - - var oldRangeStart = 0, newRangeStart = 0, curRange = [], - oldLine = 1, newLine = 1; - for (var i = 0; i < diff.length; i++) { - var current = diff[i], - lines = current.lines || current.value.replace(/\n$/, '').split('\n'); - current.lines = lines; - - if (current.added || current.removed) { - // If we have previous context, start with that - if (!oldRangeStart) { - var prev = diff[i - 1]; - oldRangeStart = oldLine; - newRangeStart = newLine; - - if (prev) { - curRange = contextLines(prev.lines.slice(-4)); - oldRangeStart -= curRange.length; - newRangeStart -= curRange.length; - } - } - - // Output our changes - curRange.push.apply(curRange, map(lines, function (entry) { - return (current.added ? '+' : '-') + entry; - })); - eofNL(curRange, i, current); - - // Track the updated file position - if (current.added) { - newLine += lines.length; - } else { - oldLine += lines.length; - } - } else { - // Identical context lines. Track line changes - if (oldRangeStart) { - // Close out any changes that have been output (or join overlapping) - if (lines.length <= 8 && i < diff.length - 2) { - // Overlapping - curRange.push.apply(curRange, contextLines(lines)); - } else { - // end the range and output - var contextSize = Math.min(lines.length, 4); - ret.push( - '@@ -' + oldRangeStart + ',' + (oldLine - oldRangeStart + contextSize) - + ' +' + newRangeStart + ',' + (newLine - newRangeStart + contextSize) - + ' @@'); - ret.push.apply(ret, curRange); - ret.push.apply(ret, contextLines(lines.slice(0, contextSize))); - if (lines.length <= 4) { - eofNL(ret, i, current); - } - - oldRangeStart = 0; - newRangeStart = 0; - curRange = []; - } - } - oldLine += lines.length; - newLine += lines.length; - } - } - - return ret.join('\n') + '\n'; - }, - - createPatch: function (fileName, oldStr, newStr, oldHeader, newHeader) { - return JsDiff.createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader); - }, - - applyPatch: function (oldStr, uniDiff) { - var diffstr = uniDiff.split('\n'), - hunks = [], - i = 0, - remEOFNL = false, - addEOFNL = false; - - // Skip to the first change hunk - while (i < diffstr.length && !(/^@@/.test(diffstr[i]))) { - i++; - } - - // Parse the unified diff - for (; i < diffstr.length; i++) { - if (diffstr[i][0] === '@') { - var chnukHeader = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/); - hunks.unshift({ - start: chnukHeader[3], - oldlength: +chnukHeader[2], - removed: [], - newlength: chnukHeader[4], - added: [] - }); - } else if (diffstr[i][0] === '+') { - hunks[0].added.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === '-') { - hunks[0].removed.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === ' ') { - hunks[0].added.push(diffstr[i].substr(1)); - hunks[0].removed.push(diffstr[i].substr(1)); - } else if (diffstr[i][0] === '\\') { - if (diffstr[i - 1][0] === '+') { - remEOFNL = true; - } else if (diffstr[i - 1][0] === '-') { - addEOFNL = true; - } - } - } - - // Apply the diff to the input - var lines = oldStr.split('\n'); - for (i = hunks.length - 1; i >= 0; i--) { - var hunk = hunks[i]; - // Sanity check the input string. Bail if we don't match. - for (var j = 0; j < hunk.oldlength; j++) { - if (lines[hunk.start - 1 + j] !== hunk.removed[j]) { - return false; - } - } - Array.prototype.splice.apply(lines, [hunk.start - 1, hunk.oldlength].concat(hunk.added)); - } - - // Handle EOFNL insertion/removal - if (remEOFNL) { - while (!lines[lines.length - 1]) { - lines.pop(); - } - } else if (addEOFNL) { - lines.push(''); - } - return lines.join('\n'); - }, - - convertChangesToXML: function (changes) { - var ret = []; - for (var i = 0; i < changes.length; i++) { - var change = changes[i]; - if (change.added) { - ret.push(''); - } else if (change.removed) { - ret.push(''); - } - - ret.push(escapeHTML(change.value)); - - if (change.added) { - ret.push(''); - } else if (change.removed) { - ret.push(''); - } - } - return ret.join(''); - }, - - // See: http://code.google.com/p/google-diff-match-patch/wiki/API - convertChangesToDMP: function (changes) { - var ret = [], - change, - operation; - for (var i = 0; i < changes.length; i++) { - change = changes[i]; - if (change.added) { - operation = 1; - } else if (change.removed) { - operation = -1; - } else { - operation = 0; - } - - ret.push([operation, change.value]); - } - return ret; - }, - - canonicalize: canonicalize - }; - - /*istanbul ignore next */ - /*global module */ - if (typeof module !== 'undefined' && module.exports) { - module.exports = JsDiff; - } else if (typeof define === 'function' && define.amd) { - /*global define */ - define([], function () { - return JsDiff; - }); - } else if (typeof global.JsDiff === 'undefined') { - global.JsDiff = JsDiff; - } -}(this)); diff --git a/lib/fakeRequire.js b/lib/fakeRequire.js deleted file mode 100644 index a9ee153..0000000 --- a/lib/fakeRequire.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Hack to allow nodejs require("package/file") in the browser - * How? - * Since every require is used as an object: - * `require("./utils.js").Utils` // (notice the `.Utils`) - * - * We can say that when there is no require method - * we use the global object in which the `Utils` - * object was already injected. - */ - -var $globalHolder = (typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof this !== 'undefined' && this) || - Function('return this')(); -function require() { - return $globalHolder; -} diff --git a/package.json b/package.json index 2bbc26c..4fba4e2 100644 --- a/package.json +++ b/package.json @@ -1,67 +1,50 @@ { - "name": "diff2html", - "version": "0.2.6-1", + "name": "diff2html", + "version": "0.2.7-1", "homepage": "http://rtfpessoa.github.io/diff2html/", "description": "Fast Diff to colorized HTML", "keywords": [ - "git", - "diff", - "pretty", - "side", - "line", - "side-by-side", - "line-by-line", - "character", - "highlight", - "pretty", - "color", - "html", - "diff2html", - "difftohtml", - "colorized" - ], - + "git", + "diff", + "pretty", + "side", + "line", + "side-by-side", + "line-by-line", + "character", + "highlight", + "pretty", + "color", + "html", + "diff2html", + "difftohtml", + "colorized" + ], "author": { - "name": "Rodrigo Fernandes", + "name": "Rodrigo Fernandes", "email": "rtfrodrigo@gmail.com" }, - "repository": { "type": "git", "url": "https://www.github.com/rtfpessoa/diff2html.git" }, - "bugs": { "url": "https://www.github.com/rtfpessoa/diff2html/issues" }, - "engines": { - "node": ">=0.10" + "node": ">=0.10" }, - "preferGlobal": "true", - "scripts": { "test": "" }, - - "bin": { - "diff2html-lib": "./bin/diff2html" - }, - "main": "./src/diff2html.js", - "dependencies": { - "diff": "1.4.0" + "diff": "2.0.1" }, - "devDependencies": {}, - "license": "MIT", - "files": [ - "bin", - "lib", "src" ] } diff --git a/release.sh b/release.sh index 4d77c68..fe066c6 100755 --- a/release.sh +++ b/release.sh @@ -1,7 +1,8 @@ #!/bin/bash # -# Diff2Html release script +# diff2html release script +# by rtfpessoa # OUTPUT_DIR=dist @@ -10,7 +11,7 @@ OUTPUT_MIN_JS_FILE=${OUTPUT_DIR}/diff2html.min.js OUTPUT_CSS_FILE=${OUTPUT_DIR}/diff2html.css OUTPUT_MIN_CSS_FILE=${OUTPUT_DIR}/diff2html.min.css -echo "Creating Diff2Html release ..." +echo "Creating diff2html release ..." echo "Cleaning previous versions ..." rm -rf ${OUTPUT_DIR} @@ -18,16 +19,7 @@ mkdir -p ${OUTPUT_DIR} echo "Generating js aggregation file in ${OUTPUT_JS_FILE}" -echo "// Diff2Html minifier version (automatically generated)" > ${OUTPUT_JS_FILE} -cat lib/fakeRequire.js >> ${OUTPUT_JS_FILE} -cat lib/diff.js >> ${OUTPUT_JS_FILE} -cat src/utils.js >> ${OUTPUT_JS_FILE} -cat src/diff-parser.js >> ${OUTPUT_JS_FILE} -cat src/printer-utils.js >> ${OUTPUT_JS_FILE} -cat src/side-by-side-printer.js >> ${OUTPUT_JS_FILE} -cat src/line-by-line-printer.js >> ${OUTPUT_JS_FILE} -cat src/html-printer.js >> ${OUTPUT_JS_FILE} -cat src/diff2html.js >> ${OUTPUT_JS_FILE} +webpack ./src/diff2html.js ${OUTPUT_JS_FILE} echo "Minifying ${OUTPUT_JS_FILE} to ${OUTPUT_MIN_JS_FILE}" @@ -41,4 +33,4 @@ echo "Minifying ${OUTPUT_CSS_FILE} to ${OUTPUT_MIN_CSS_FILE}" lessc -x ${OUTPUT_CSS_FILE} ${OUTPUT_MIN_CSS_FILE} -echo "Diff2Html release created successfully!" +echo "diff2html release created successfully!" diff --git a/sample/index.html b/sample/index.html index 0116fa0..ae3a95a 100644 --- a/sample/index.html +++ b/sample/index.html @@ -11,19 +11,6 @@ - - @@ -217,17 +204,17 @@ '+\n' + '+console.log(parser.parsePatchDiffResult(text, patchLineList));\n'; - document.addEventListener("DOMContentLoaded", function () { + document.addEventListener("DOMContentLoaded", function() { // parse the diff to json var diffJson = Diff2Html.getJsonFromDiff(lineDiffExample); // collect all the file extensions in the json - var allFileLanguages = diffJson.map(function (line) { + var allFileLanguages = diffJson.map(function(line) { return line.language; }); // remove duplicated languages - var distinctLanguages = allFileLanguages.filter(function (v, i) { + var distinctLanguages = allFileLanguages.filter(function(v, i) { return allFileLanguages.indexOf(v) == i; }); @@ -240,7 +227,7 @@ // collect all the code lines and execute the highlight on them var codeLines = document.getElementsByClassName("d2h-code-line-ctn"); - [].forEach.call(codeLines, function (line) { + [].forEach.call(codeLines, function(line) { hljs.highlightBlock(line); }); }); diff --git a/src/diff-parser.js b/src/diff-parser.js index 1bd9a07..9587cbf 100644 --- a/src/diff-parser.js +++ b/src/diff-parser.js @@ -5,15 +5,15 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - var utils = require("./utils.js").Utils; + var utils = require('./utils.js').Utils; var LINE_TYPE = { - INSERTS: "d2h-ins", - DELETES: "d2h-del", - CONTEXT: "d2h-cntx", - INFO: "d2h-info" + INSERTS: 'd2h-ins', + DELETES: 'd2h-del', + CONTEXT: 'd2h-cntx', + INFO: 'd2h-info' }; function DiffParser() { @@ -21,24 +21,24 @@ DiffParser.prototype.LINE_TYPE = LINE_TYPE; - DiffParser.prototype.generateDiffJson = function (diffInput) { - var files = [], - currentFile = null, - currentBlock = null, - oldLine = null, - newLine = null; + DiffParser.prototype.generateDiffJson = function(diffInput) { + var files = []; + var currentFile = null; + var currentBlock = null; + var oldLine = null; + var newLine = null; - var saveBlock = function () { - /* add previous block(if exists) before start a new file */ + var saveBlock = function() { + /* Add previous block(if exists) before start a new file */ if (currentBlock) { currentFile.blocks.push(currentBlock); currentBlock = null; } }; - var saveFile = function () { + var saveFile = function() { /* - * add previous file(if exists) before start a new one + * Add previous file(if exists) before start a new one * if it has name (to avoid binary files errors) */ if (currentFile && currentFile.newName) { @@ -47,18 +47,18 @@ } }; - var startFile = function () { + var startFile = function() { saveBlock(); saveFile(); - /* create file structure */ + /* Create file structure */ currentFile = {}; currentFile.blocks = []; currentFile.deletedLines = 0; currentFile.addedLines = 0; }; - var startBlock = function (line) { + var startBlock = function(line) { saveBlock(); var values; @@ -75,7 +75,7 @@ oldLine = values[1]; newLine = values[2]; - /* create block metadata */ + /* Create block metadata */ currentBlock = {}; currentBlock.lines = []; currentBlock.oldStartLine = oldLine; @@ -83,12 +83,12 @@ currentBlock.header = line; }; - var createLine = function (line) { + var createLine = function(line) { var currentLine = {}; currentLine.content = line; - /* fill the line data */ - if (utils.startsWith(line, "+") || utils.startsWith(line, " +")) { + /* Fill the line data */ + if (utils.startsWith(line, '+') || utils.startsWith(line, ' +')) { currentFile.addedLines++; currentLine.type = LINE_TYPE.INSERTS; @@ -97,7 +97,7 @@ currentBlock.lines.push(currentLine); - } else if (utils.startsWith(line, "-") || utils.startsWith(line, " -")) { + } else if (utils.startsWith(line, '-') || utils.startsWith(line, ' -')) { currentFile.deletedLines++; currentLine.type = LINE_TYPE.DELETES; @@ -115,13 +115,12 @@ } }; - var diffLines = diffInput.split("\n"); - diffLines.forEach(function (line) { + var diffLines = diffInput.split('\n'); + diffLines.forEach(function(line) { // Unmerged paths, and possibly other non-diffable files // https://github.com/scottgonzalez/pretty-diff/issues/11 // Also, remove some useless lines - if (!line || utils.startsWith(line, "*")) { - //|| utils.startsWith(line, "new") || utils.startsWith(line, "index") + if (!line || utils.startsWith(line, '*')) { return; } @@ -148,7 +147,7 @@ var combinedDeletedFile = /^deleted file mode (\d{6}),(\d{6})/; var values = []; - if (utils.startsWith(line, "diff")) { + if (utils.startsWith(line, 'diff')) { startFile(); } else if (currentFile && !currentFile.oldName && (values = /^--- a\/(\S+).*$/.exec(line))) { currentFile.oldName = values[1]; @@ -156,7 +155,7 @@ } else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [b]?\/(\S+).*$/.exec(line))) { currentFile.newName = values[1]; currentFile.language = getExtension(currentFile.newName, currentFile.language); - } else if (currentFile && utils.startsWith(line, "@@")) { + } else if (currentFile && utils.startsWith(line, '@@')) { startBlock(line); } else if ((values = oldMode.exec(line))) { currentFile.oldMode = values[1]; @@ -208,17 +207,14 @@ }; function getExtension(filename, language) { - var nameSplit = filename.split("."); - if (nameSplit.length > 1) return nameSplit[nameSplit.length - 1]; - else return language; + var nameSplit = filename.split('.'); + if (nameSplit.length > 1) { + return nameSplit[nameSplit.length - 1]; + } else { + return language; + } } - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["DiffParser"] = new DiffParser(); + module.exports['DiffParser'] = new DiffParser(); })(this); diff --git a/src/diff2html.js b/src/diff2html.js index 63c733d..23fad78 100644 --- a/src/diff2html.js +++ b/src/diff2html.js @@ -5,10 +5,10 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - var diffParser = require("./diff-parser.js").DiffParser; - var htmlPrinter = require("./html-printer.js").HtmlPrinter; + var diffParser = require('./diff-parser.js').DiffParser; + var htmlPrinter = require('./html-printer.js').HtmlPrinter; function Diff2Html() { } @@ -25,7 +25,7 @@ /* * Generates pretty html from string diff input */ - Diff2Html.prototype.getPrettyHtmlFromDiff = function (diffInput, config) { + Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { var diffJson = diffParser.generateDiffJson(diffInput); var configOrEmpty = config || {}; return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); @@ -34,14 +34,14 @@ /* * Generates json object from string diff input */ - Diff2Html.prototype.getJsonFromDiff = function (diffInput) { + Diff2Html.prototype.getJsonFromDiff = function(diffInput) { return diffParser.generateDiffJson(diffInput); }; /* * Generates pretty html from a json object */ - Diff2Html.prototype.getPrettyHtmlFromJson = function (diffJson, config) { + Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); }; @@ -49,7 +49,7 @@ /* * Generates pretty side by side html from string diff input */ - Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput, config) { + Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) { var diffJson = diffParser.generateDiffJson(diffInput); var configOrEmpty = config || {}; @@ -59,17 +59,15 @@ /* * Generates pretty side by side html from a json object */ - Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function (diffJson, config) { + Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) { var configOrEmpty = config || {}; return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); }; - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["Diff2Html"] = new Diff2Html(); + var diffName = 'Diff2Html'; + var diffObject = new Diff2Html(); + module.exports[diffName] = diffObject; + // Expose diff2html in the browser + global[diffName] = diffObject; })(this); diff --git a/src/html-printer.js b/src/html-printer.js index 0f9a99c..aa3588f 100644 --- a/src/html-printer.js +++ b/src/html-printer.js @@ -5,10 +5,10 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - var lineByLinePrinter = require("./line-by-line-printer.js").LineByLinePrinter; - var sideBySidePrinter = require("./side-by-side-printer.js").SideBySidePrinter; + var lineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter; + var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter; function HtmlPrinter() { } @@ -17,12 +17,6 @@ HtmlPrinter.prototype.generateSideBySideJsonHtml = sideBySidePrinter.generateSideBySideJsonHtml; - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["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 78fdf8b..bc5a1a0 100644 --- a/src/line-by-line-printer.js +++ b/src/line-by-line-printer.js @@ -5,57 +5,62 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - var diffParser = require("./diff-parser.js").DiffParser; - var printerUtils = require("./printer-utils.js").PrinterUtils; - var utils = require("./utils.js").Utils; + var diffParser = require('./diff-parser.js').DiffParser; + var printerUtils = require('./printer-utils.js').PrinterUtils; + var utils = require('./utils.js').Utils; function LineByLinePrinter() { } - LineByLinePrinter.prototype.generateLineByLineJsonHtml = function (diffFiles, config) { - return "
\n" + - diffFiles.map(function (file) { + LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) { + return '
\n' + + diffFiles.map(function(file) { var diffs; - if (file.blocks.length) diffs = generateFileHtml(file, config); - else diffs = generateEmptyDiff(); + if (file.blocks.length) { + diffs = generateFileHtml(file, config); + } else { + diffs = generateEmptyDiff(); + } - return "
\n" + - "
\n" + - "
\n" + - " +" + file.addedLines + "\n" + - " -" + file.deletedLines + "\n" + - "
\n" + - "
" + printerUtils.getDiffName(file) + "
\n" + - "
\n" + - "
\n" + - "
\n" + - " \n" + - " \n" + - " " + diffs + - " \n" + - "
\n" + - "
\n" + - "
\n" + - "
\n"; - }).join("\n") + - "
\n"; + return '
\n' + + '
\n' + + '
\n' + + ' +' + file.addedLines + '\n' + + ' -' + file.deletedLines + '\n' + + '
\n' + + '
' + printerUtils.getDiffName(file) + '
\n' + + '
\n' + + '
\n' + + '
\n' + + ' \n' + + ' \n' + + ' ' + diffs + + ' \n' + + '
\n' + + '
\n' + + '
\n' + + '
\n'; + }).join('\n') + + '
\n'; }; function generateFileHtml(file, config) { - return file.blocks.map(function (block) { + return file.blocks.map(function(block) { - var lines = "\n" + - " \n" + - " " + - "
" + utils.escape(block.header) + "
" + - " \n" + - "\n"; + var lines = '\n' + + ' \n' + + ' ' + + '
' + utils.escape(block.header) + '
' + + ' \n' + + '\n'; - var oldLines = [], newLines = []; - var processedOldLines = [], processedNewLines = []; + var oldLines = []; + var newLines = []; + var processedOldLines = []; + var processedNewLines = []; for (var i = 0; i < block.lines.length; i++) { var line = block.lines[i]; @@ -81,8 +86,12 @@ config.isCombined = file.isCombined; var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); - processedOldLines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, diff.first.line, diff.first.prefix); - processedNewLines += generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, diff.second.line, diff.second.prefix); + processedOldLines += + generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, + diff.first.line, diff.first.prefix); + processedNewLines += + generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, + diff.second.line, diff.second.prefix); } lines += processedOldLines + processedNewLines; @@ -101,11 +110,11 @@ lines += processLines(oldLines, newLines); return lines; - }).join("\n"); + }).join('\n'); } function processLines(oldLines, newLines) { - var lines = ""; + var lines = ''; for (j = 0; j < oldLines.length; j++) { var oldLine = oldLines[j]; @@ -123,39 +132,37 @@ } function generateLineHtml(type, oldNumber, newNumber, content, prefix) { - var htmlPrefix = ""; - if (prefix) htmlPrefix = "" + prefix + ""; + var htmlPrefix = ''; + if (prefix) { + htmlPrefix = '' + prefix + ''; + } - var htmlContent = ""; - if (content) htmlContent = "" + content + ""; + var htmlContent = ''; + if (content) { + htmlContent = '' + content + ''; + } - return "\n" + - " " + - "
" + utils.valueOrEmpty(oldNumber) + "
" + - "
" + utils.valueOrEmpty(newNumber) + "
" + - " \n" + - " " + - "
" + htmlPrefix + htmlContent + "
" + - " \n" + - "\n"; + return '\n' + + ' ' + + '
' + utils.valueOrEmpty(oldNumber) + '
' + + '
' + utils.valueOrEmpty(newNumber) + '
' + + ' \n' + + ' ' + + '
' + htmlPrefix + htmlContent + '
' + + ' \n' + + '\n'; } function generateEmptyDiff() { - return "\n" + - " " + - "
" + - "File without changes" + - "
" + - " \n" + - "\n"; + return '\n' + + ' ' + + '
' + + 'File without changes' + + '
' + + ' \n' + + '\n'; } - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["LineByLinePrinter"] = new LineByLinePrinter(); + module.exports['LineByLinePrinter'] = new LineByLinePrinter(); })(this); diff --git a/src/printer-utils.js b/src/printer-utils.js index b8122bf..5b5b98b 100644 --- a/src/printer-utils.js +++ b/src/printer-utils.js @@ -5,38 +5,39 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - // dirty hack for browser compatibility - var jsDiff = (typeof JsDiff !== "undefined" && JsDiff) || require("diff"); - var utils = require("./utils.js").Utils; + var jsDiff = require('diff'); + var utils = require('./utils.js').Utils; function PrinterUtils() { } - PrinterUtils.prototype.getDiffName = function (file) { + PrinterUtils.prototype.getDiffName = function(file) { var oldFilename = file.oldName; var newFilename = file.newName; if (oldFilename && newFilename && oldFilename !== newFilename && !isDeletedName(newFilename)) { - return oldFilename + " -> " + 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) { + PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) { var lineStart1, lineStart2; var prefixSize = 1; - if (config.isCombined) prefixSize = 2; + if (config.isCombined) { + prefixSize = 2; + } lineStart1 = diffLine1.substr(0, prefixSize); lineStart2 = diffLine2.substr(0, prefixSize); @@ -45,17 +46,23 @@ diffLine2 = diffLine2.substr(prefixSize); var diff; - if (config.charByChar) diff = jsDiff.diffChars(diffLine1, diffLine2); - else diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); + if (config.charByChar) { + diff = jsDiff.diffChars(diffLine1, diffLine2); + } else { + diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2); + } - var highlightedLine = ""; + var highlightedLine = ''; - diff.forEach(function (part) { + diff.forEach(function(part) { var elemType = part.added ? 'ins' : part.removed ? 'del' : null; var escapedValue = utils.escape(part.value); - if (elemType !== null) highlightedLine += "<" + elemType + ">" + escapedValue + ""; - else highlightedLine += escapedValue; + if (elemType !== null) { + highlightedLine += '<' + elemType + '>' + escapedValue + ''; + } else { + highlightedLine += escapedValue; + } }); return { @@ -71,23 +78,17 @@ }; function isDeletedName(name) { - return name === "dev/null"; + return name === 'dev/null'; } function removeIns(line) { - return line.replace(/(((.|\n)*?)<\/ins>)/g, ""); + return line.replace(/(((.|\n)*?)<\/ins>)/g, ''); } function removeDel(line) { - return line.replace(/(((.|\n)*?)<\/del>)/g, ""); + return line.replace(/(((.|\n)*?)<\/del>)/g, ''); } - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["PrinterUtils"] = new PrinterUtils(); + module.exports['PrinterUtils'] = new PrinterUtils(); })(this); diff --git a/src/side-by-side-printer.js b/src/side-by-side-printer.js index 84d0f9e..1563812 100644 --- a/src/side-by-side-printer.js +++ b/src/side-by-side-printer.js @@ -5,79 +5,85 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { - var diffParser = require("./diff-parser.js").DiffParser; - var printerUtils = require("./printer-utils.js").PrinterUtils; - var utils = require("./utils.js").Utils; + var diffParser = require('./diff-parser.js').DiffParser; + var printerUtils = require('./printer-utils.js').PrinterUtils; + var utils = require('./utils.js').Utils; function SideBySidePrinter() { } - SideBySidePrinter.prototype.generateSideBySideJsonHtml = function (diffFiles, config) { - return "
\n" + - diffFiles.map(function (file) { + SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) { + return '
\n' + + diffFiles.map(function(file) { var diffs; - if (file.blocks.length) diffs = generateSideBySideFileHtml(file, config); - else diffs = generateEmptyDiff(); + if (file.blocks.length) { + diffs = generateSideBySideFileHtml(file, config); + } else { + diffs = generateEmptyDiff(); + } - return "
\n" + - "
\n" + - "
\n" + - " +" + file.addedLines + "\n" + - " -" + file.deletedLines + "\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"; + return '
\n' + + '
\n' + + '
\n' + + ' +' + file.addedLines + '\n' + + ' -' + file.deletedLines + '\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'; }; function generateSideBySideFileHtml(file, config) { var fileHtml = {}; - fileHtml.left = ""; - fileHtml.right = ""; + fileHtml.left = ''; + fileHtml.right = ''; - file.blocks.forEach(function (block) { + file.blocks.forEach(function(block) { - fileHtml.left += "\n" + - " \n" + - " " + - "
" + utils.escape(block.header) + "
" + - " \n" + - "\n"; + fileHtml.left += '\n' + + ' \n' + + ' ' + + '
' + + ' ' + utils.escape(block.header) + + '
' + + ' \n' + + '\n'; - fileHtml.right += "\n" + - " \n" + - " " + - "
" + - " \n" + - "\n"; + fileHtml.right += '\n' + + ' \n' + + ' ' + + '
' + + ' \n' + + '\n'; - var oldLines = [], newLines = []; - var tmpHtml = ""; + var oldLines = []; + var newLines = []; + var tmpHtml = ''; for (var i = 0; i < block.lines.length; i++) { var line = block.lines[i]; @@ -87,7 +93,7 @@ fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, escapedLine); fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); } else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) { - fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); + fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine); } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) { oldLines.push(line); @@ -106,8 +112,12 @@ var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, config); - fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, diff.first.line, diff.first.prefix); - fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, diff.second.line, diff.second.prefix); + fileHtml.left += + generateSingleLineHtml(oldLine.type, oldLine.oldNumber, + diff.first.line, diff.first.prefix); + fileHtml.right += + generateSingleLineHtml(newLine.type, newLine.newNumber, + diff.second.line, diff.second.prefix); } } else { tmpHtml = processLines(oldLines, newLines); @@ -131,8 +141,8 @@ function processLines(oldLines, newLines) { var fileHtml = {}; - fileHtml.left = ""; - fileHtml.right = ""; + fileHtml.left = ''; + fileHtml.right = ''; var maxLinesNumber = Math.max(oldLines.length, newLines.length); for (j = 0; j < maxLinesNumber; j++) { @@ -144,12 +154,12 @@ fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); } else if (oldLine) { fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content)); - fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); + fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); } else if (newLine) { - fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", ""); + fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', ''); fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content)); } else { - console.error("How did it get here?"); + console.error('How did it get here?'); } } @@ -157,41 +167,39 @@ } function generateSingleLineHtml(type, number, content, prefix) { - var htmlPrefix = ""; - if (prefix) htmlPrefix = "" + prefix + ""; + var htmlPrefix = ''; + if (prefix) { + htmlPrefix = '' + prefix + ''; + } - var htmlContent = ""; - if (content) htmlContent = "" + content + ""; + var htmlContent = ''; + if (content) { + htmlContent = '' + content + ''; + } - return "\n" + - " " + number + "\n" + - " " + - "
" + htmlPrefix + htmlContent + "
" + - " \n" + - " \n"; + return '\n' + + ' ' + number + '\n' + + ' ' + + '
' + htmlPrefix + htmlContent + '
' + + ' \n' + + ' \n'; } function generateEmptyDiff() { var fileHtml = {}; - fileHtml.right = ""; + fileHtml.right = ''; - fileHtml.left = "\n" + - " " + - "
" + - "File without changes" + - "
" + - " \n" + - "\n"; + fileHtml.left = '\n' + + ' ' + + '
' + + 'File without changes' + + '
' + + ' \n' + + '\n'; return fileHtml; } - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["SideBySidePrinter"] = new SideBySidePrinter(); + module.exports['SideBySidePrinter'] = new SideBySidePrinter(); })(this); diff --git a/src/utils.js b/src/utils.js index 43eff7f..56c30de 100644 --- a/src/utils.js +++ b/src/utils.js @@ -5,33 +5,27 @@ * */ -(function (ctx, undefined) { +(function(ctx, undefined) { function Utils() { } - Utils.prototype.escape = function (str) { + Utils.prototype.escape = function(str) { return str.slice(0) - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/\t/g, " "); + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/\t/g, ' '); }; - Utils.prototype.startsWith = function (str, start) { + Utils.prototype.startsWith = function(str, start) { return str.indexOf(start) === 0; }; - Utils.prototype.valueOrEmpty = function (value) { - return value ? value : ""; + Utils.prototype.valueOrEmpty = function(value) { + return value ? value : ''; }; - // expose this module - ((typeof module !== 'undefined' && module.exports) || - (typeof exports !== 'undefined' && exports) || - (typeof window !== 'undefined' && window) || - (typeof self !== 'undefined' && self) || - (typeof $this !== 'undefined' && $this) || - Function('return this')())["Utils"] = new Utils(); + module.exports['Utils'] = new Utils(); })(this);