diff2html
Advanced tools
Comparing version 0.1.5 to 0.1.6-1
{ | ||
"name": "diff2html", | ||
"version": "0.1.5", | ||
"version": "0.1.6-1", | ||
@@ -56,4 +56,4 @@ "homepage": "https://www.github.com/rtfpessoa/diff2html-nodejs", | ||
"dependencies": { | ||
"commander": "2.2.0", | ||
"extend": "1.2.1", | ||
"commander": "2.6.0", | ||
"extend": "2.0.0", | ||
"pkginfo": "0.3.0", | ||
@@ -75,4 +75,5 @@ "execSync": "1.0.2" | ||
"bin", | ||
"src" | ||
"src", | ||
"dist" | ||
] | ||
} |
@@ -6,3 +6,3 @@ /* | ||
* Date: Friday 29 August 2014 | ||
* Last Update: Saturday 27 September 2014 | ||
* Last Update: Saturday 24 January 2015 | ||
* | ||
@@ -14,6 +14,6 @@ * Diff commands: | ||
module.exports = (function () { | ||
var diffString = require("./lib/jsdiff.js"); | ||
var ClassVariable; | ||
var jsdiff = require("./lib/jsdiff.js"); | ||
ClassVariable = (function () { | ||
@@ -84,4 +84,7 @@ | ||
var saveFile = function () { | ||
/* add previous file(if exists) before start a new one */ | ||
if (currentFile) { | ||
/* | ||
* 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); | ||
@@ -92,3 +95,3 @@ currentFile = null; | ||
var startFile = function (line) { | ||
var startFile = function () { | ||
saveBlock(); | ||
@@ -102,7 +105,2 @@ saveFile(); | ||
currentFile.addedLines = 0; | ||
/* save file paths, before and after the diff */ | ||
var values = /^diff --git a\/(\S+) b\/(\S+).*$/.exec(line); | ||
currentFile.oldName = values[1]; | ||
currentFile.newName = values[2]; | ||
}; | ||
@@ -113,11 +111,9 @@ | ||
var values; | ||
if (values = /^(@@ -(\d+),(\d+) \+(\d+),(\d+) @@).*/.exec(line)) { | ||
oldLine = values[2]; | ||
newLine = values[4]; | ||
} else { | ||
oldLine = 0; | ||
newLine = 0; | ||
} | ||
var values = /^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line) || | ||
/^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line) || | ||
[0, 0, 0]; | ||
oldLine = values[1]; | ||
newLine = values[2]; | ||
/* create block metadata */ | ||
@@ -136,3 +132,3 @@ currentBlock = {}; | ||
/* fill the line data */ | ||
if (startsWith(line, "+")) { | ||
if (startsWith(line, "+") || startsWith(line, " +")) { | ||
currentFile.addedLines++; | ||
@@ -146,3 +142,3 @@ | ||
} else if (startsWith(line, "-")) { | ||
} else if (startsWith(line, "-") || startsWith(line, " -")) { | ||
currentFile.deletedLines++; | ||
@@ -171,9 +167,13 @@ | ||
if (!line || startsWith(line, "*") || | ||
startsWith(line, "new") || startsWith(line, "index") || | ||
startsWith(line, "---") || startsWith(line, "+++")) { | ||
startsWith(line, "new") || startsWith(line, "index")) { | ||
return; | ||
} | ||
var values = []; | ||
if (startsWith(line, "diff")) { | ||
startFile(line); | ||
startFile(); | ||
} else if (currentFile && !currentFile.oldName && (values = /^--- a\/(\S+).*$/.exec(line))) { | ||
currentFile.oldName = values[1]; | ||
} else if (currentFile && !currentFile.newName && (values = /^\+\+\+ b\/(\S+).*$/.exec(line))) { | ||
currentFile.newName = values[1]; | ||
} else if (currentFile && startsWith(line, "@@")) { | ||
@@ -251,3 +251,3 @@ startBlock(line); | ||
lines += generateLineHtml(line.type, line.oldNumber, line.newNumber, diff.o) + | ||
generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, diff.n); | ||
generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, diff.n); | ||
@@ -326,14 +326,14 @@ i++; | ||
fileHtml.left += "<tr>\n" + | ||
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" + | ||
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" + | ||
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\">" + escape(block.header) + "</div>" + | ||
" </td>\n" + | ||
"</tr>\n"; | ||
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" + | ||
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" + | ||
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\">" + escape(block.header) + "</div>" + | ||
" </td>\n" + | ||
"</tr>\n"; | ||
fileHtml.right += "<tr>\n" + | ||
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" + | ||
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" + | ||
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\"></div>" + | ||
" </td>\n" + | ||
"</tr>\n"; | ||
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" + | ||
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" + | ||
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\"></div>" + | ||
" </td>\n" + | ||
"</tr>\n"; | ||
@@ -379,3 +379,3 @@ for (var i = 0; i < block.lines.length; i++) { | ||
var generateSingleLineHtml = function (type, number, content) { | ||
return"<tr>\n" + | ||
return "<tr>\n" + | ||
" <td class=\"d2h-code-side-linenumber " + type + "\">" + number + "</td>\n" + | ||
@@ -393,3 +393,11 @@ " <td class=\"" + type + "\">" + | ||
var getDiffName = function (oldFilename, newFilename) { | ||
return oldFilename === newFilename ? newFilename : oldFilename + " -> " + newFilename; | ||
if (oldFilename && newFilename && oldFilename !== newFilename) { | ||
return oldFilename + " -> " + newFilename; | ||
} else if (newFilename) { | ||
return newFilename; | ||
} else if (oldFilename) { | ||
return oldFilename; | ||
} else { | ||
return "Unknown filename"; | ||
} | ||
}; | ||
@@ -427,3 +435,3 @@ | ||
/* remove the initial -/+ to avoid always having diff in the first char */ | ||
var highlightedLine = jsdiff.diffString(diffLine1.substr(1), diffLine2.substr(1)); | ||
var highlightedLine = diffString(diffLine1.substr(1), diffLine2.substr(1)); | ||
@@ -430,0 +438,0 @@ return { |
@@ -5,3 +5,3 @@ /* | ||
* Modified by Chu Alan "sprite" | ||
* Modified by Rodrigo Fernandes (rtfpessoa) | ||
* Modified by Rodrigo Fernandes "rtfpessoa" | ||
* | ||
@@ -14,3 +14,3 @@ * Released under the MIT license. | ||
this.diffString = function (o, n) { | ||
module.exports = function (o, n) { | ||
o = o.replace(/\s+$/, ''); | ||
@@ -37,3 +37,3 @@ n = n.replace(/\s+$/, ''); | ||
for (var i = 0; i < out.o.length; i++) { | ||
str += '<del>' + escape(out.o[i]) + oSpace[i] + "</del>"; | ||
str += '<del>' + out.o[i] + oSpace[i] + "</del>"; | ||
} | ||
@@ -43,3 +43,3 @@ } else { | ||
for (n = 0; n < out.o.length && out.o[n].text == null; n++) { | ||
str += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>"; | ||
str += '<del>' + out.o[n] + oSpace[n] + "</del>"; | ||
} | ||
@@ -50,3 +50,3 @@ } | ||
if (out.n[i].text == null) { | ||
str += '<ins>' + escape(out.n[i]) + nSpace[i] + "</ins>"; | ||
str += '<ins>' + out.n[i] + nSpace[i] + "</ins>"; | ||
} else { | ||
@@ -56,3 +56,3 @@ var pre = ""; | ||
for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) { | ||
pre += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>"; | ||
pre += '<del>' + out.o[n] + oSpace[n] + "</del>"; | ||
} | ||
@@ -65,12 +65,2 @@ str += " " + out.n[i].text + nSpace[i] + pre; | ||
return str; | ||
}; | ||
function escape(s) { | ||
var n = s; | ||
n = n.replace(/&/g, "&"); | ||
n = n.replace(/</g, "<"); | ||
n = n.replace(/>/g, ">"); | ||
n = n.replace(/"/g, """); | ||
return n; | ||
} | ||
@@ -83,11 +73,11 @@ | ||
for (var i = 0; i < n.length; i++) { | ||
if (ns[ n[i] ] == null) | ||
ns[ n[i] ] = { rows: new Array(), o: null }; | ||
ns[ n[i] ].rows.push(i); | ||
if (ns[n[i]] == null) | ||
ns[n[i]] = {rows: new Array(), o: null}; | ||
ns[n[i]].rows.push(i); | ||
} | ||
for (var i = 0; i < o.length; i++) { | ||
if (os[ o[i] ] == null) | ||
os[ o[i] ] = { rows: new Array(), n: null }; | ||
os[ o[i] ].rows.push(i); | ||
if (os[o[i]] == null) | ||
os[o[i]] = {rows: new Array(), n: null}; | ||
os[o[i]].rows.push(i); | ||
} | ||
@@ -97,4 +87,4 @@ | ||
if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) { | ||
n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] }; | ||
o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] }; | ||
n[ns[i].rows[0]] = {text: n[ns[i].rows[0]], row: os[i].rows[0]}; | ||
o[os[i].rows[0]] = {text: o[os[i].rows[0]], row: ns[i].rows[0]}; | ||
} | ||
@@ -104,6 +94,6 @@ } | ||
for (var i = 0; i < n.length - 1; i++) { | ||
if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && | ||
n[i + 1] == o[ n[i].row + 1 ]) { | ||
n[i + 1] = { text: n[i + 1], row: n[i].row + 1 }; | ||
o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1 }; | ||
if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[n[i].row + 1].text == null && | ||
n[i + 1] == o[n[i].row + 1]) { | ||
n[i + 1] = {text: n[i + 1], row: n[i].row + 1}; | ||
o[n[i].row + 1] = {text: o[n[i].row + 1], row: i + 1}; | ||
} | ||
@@ -113,10 +103,10 @@ } | ||
for (var i = n.length - 1; i > 0; i--) { | ||
if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && | ||
n[i - 1] == o[ n[i].row - 1 ]) { | ||
n[i - 1] = { text: n[i - 1], row: n[i].row - 1 }; | ||
o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1 }; | ||
if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[n[i].row - 1].text == null && | ||
n[i - 1] == o[n[i].row - 1]) { | ||
n[i - 1] = {text: n[i - 1], row: n[i].row - 1}; | ||
o[n[i].row - 1] = {text: o[n[i].row - 1], row: i - 1}; | ||
} | ||
} | ||
return { o: o, n: n }; | ||
return {o: o, n: n}; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30569
9
685
+ Addedcommander@2.6.0(transitive)
+ Addedextend@2.0.0(transitive)
- Removedcommander@2.2.0(transitive)
- Removedextend@1.2.1(transitive)
Updatedcommander@2.6.0
Updatedextend@2.0.0