fix new and delete line identification
* add different prefixes for simple and combined diffs
This commit is contained in:
parent
de13e9506c
commit
861459931b
6 changed files with 46 additions and 8 deletions
18
dist/diff2html.js
vendored
18
dist/diff2html.js
vendored
|
|
@ -213,8 +213,11 @@
|
||||||
var currentLine = {};
|
var currentLine = {};
|
||||||
currentLine.content = line;
|
currentLine.content = line;
|
||||||
|
|
||||||
|
var newLinePrefixes = !currentFile.isCombined ? ['+'] : ['+', ' +'];
|
||||||
|
var delLinePrefixes = !currentFile.isCombined ? ['-'] : ['-', ' -'];
|
||||||
|
|
||||||
/* Fill the line data */
|
/* Fill the line data */
|
||||||
if (utils.startsWith(line, '+') || utils.startsWith(line, ' +')) {
|
if (utils.startsWith(line, newLinePrefixes)) {
|
||||||
currentFile.addedLines++;
|
currentFile.addedLines++;
|
||||||
|
|
||||||
currentLine.type = LINE_TYPE.INSERTS;
|
currentLine.type = LINE_TYPE.INSERTS;
|
||||||
|
|
@ -223,7 +226,7 @@
|
||||||
|
|
||||||
currentBlock.lines.push(currentLine);
|
currentBlock.lines.push(currentLine);
|
||||||
|
|
||||||
} else if (utils.startsWith(line, '-') || utils.startsWith(line, ' -')) {
|
} else if (utils.startsWith(line, delLinePrefixes)) {
|
||||||
currentFile.deletedLines++;
|
currentFile.deletedLines++;
|
||||||
|
|
||||||
currentLine.type = LINE_TYPE.DELETES;
|
currentLine.type = LINE_TYPE.DELETES;
|
||||||
|
|
@ -371,6 +374,17 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.startsWith = function(str, start) {
|
Utils.prototype.startsWith = function(str, start) {
|
||||||
|
if (typeof start === 'object') {
|
||||||
|
var result = false;
|
||||||
|
start.forEach(function(s) {
|
||||||
|
if (str.indexOf(s) === 0) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return str.indexOf(start) === 0;
|
return str.indexOf(start) === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
2
dist/diff2html.min.js
vendored
2
dist/diff2html.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "diff2html",
|
"name": "diff2html",
|
||||||
"version": "0.2.7-1",
|
"version": "1.0.0-1",
|
||||||
"homepage": "http://rtfpessoa.github.io/diff2html/",
|
"homepage": "http://rtfpessoa.github.io/diff2html/",
|
||||||
"description": "Fast Diff to colorized HTML",
|
"description": "Fast Diff to colorized HTML",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
},
|
},
|
||||||
"main": "./src/diff2html.js",
|
"main": "./src/diff2html.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"diff": "2.0.1"
|
"diff": "1.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,17 @@
|
||||||
"+var text = 'diff --git a/components/app/app.html b/components/app/app.html\\nindex ecb7a95..027bd9b 100644\\n--- a/components/app/app.html\\n+++ b/components/app/app.html\\n@@ -52,0 +53,3 @@\\n+\\n+\\n+\\n@@ -56,0 +60,3 @@\\n+\\n+\\n+\\n'\n" +
|
"+var text = 'diff --git a/components/app/app.html b/components/app/app.html\\nindex ecb7a95..027bd9b 100644\\n--- a/components/app/app.html\\n+++ b/components/app/app.html\\n@@ -52,0 +53,3 @@\\n+\\n+\\n+\\n@@ -56,0 +60,3 @@\\n+\\n+\\n+\\n'\n" +
|
||||||
'+var patchLineList = [ false, false, false, false ];\n' +
|
'+var patchLineList = [ false, false, false, false ];\n' +
|
||||||
'+\n' +
|
'+\n' +
|
||||||
'+console.log(parser.parsePatchDiffResult(text, patchLineList));\n';
|
'+console.log(parser.parsePatchDiffResult(text, patchLineList));\n' +
|
||||||
|
"diff --git a/a.xml b/b.xml\n" +
|
||||||
|
"index e54317e..82a9a56 100644\n" +
|
||||||
|
"--- a/a.xml\n" +
|
||||||
|
"+++ b/b.xml\n" +
|
||||||
|
"@@ -242,4 +242,6 @@ need to create a new job for native server java api and move these tests to a ne\n" +
|
||||||
|
" </packages>\n" +
|
||||||
|
" </test>\n" +
|
||||||
|
" -->\n" +
|
||||||
|
"+\n" +
|
||||||
|
"+\n";
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
// parse the diff to json
|
// parse the diff to json
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,11 @@
|
||||||
var currentLine = {};
|
var currentLine = {};
|
||||||
currentLine.content = line;
|
currentLine.content = line;
|
||||||
|
|
||||||
|
var newLinePrefixes = !currentFile.isCombined ? ['+'] : ['+', ' +'];
|
||||||
|
var delLinePrefixes = !currentFile.isCombined ? ['-'] : ['-', ' -'];
|
||||||
|
|
||||||
/* Fill the line data */
|
/* Fill the line data */
|
||||||
if (utils.startsWith(line, '+') || utils.startsWith(line, ' +')) {
|
if (utils.startsWith(line, newLinePrefixes)) {
|
||||||
currentFile.addedLines++;
|
currentFile.addedLines++;
|
||||||
|
|
||||||
currentLine.type = LINE_TYPE.INSERTS;
|
currentLine.type = LINE_TYPE.INSERTS;
|
||||||
|
|
@ -97,7 +100,7 @@
|
||||||
|
|
||||||
currentBlock.lines.push(currentLine);
|
currentBlock.lines.push(currentLine);
|
||||||
|
|
||||||
} else if (utils.startsWith(line, '-') || utils.startsWith(line, ' -')) {
|
} else if (utils.startsWith(line, delLinePrefixes)) {
|
||||||
currentFile.deletedLines++;
|
currentFile.deletedLines++;
|
||||||
|
|
||||||
currentLine.type = LINE_TYPE.DELETES;
|
currentLine.type = LINE_TYPE.DELETES;
|
||||||
|
|
|
||||||
11
src/utils.js
11
src/utils.js
|
|
@ -19,6 +19,17 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Utils.prototype.startsWith = function(str, start) {
|
Utils.prototype.startsWith = function(str, start) {
|
||||||
|
if (typeof start === 'object') {
|
||||||
|
var result = false;
|
||||||
|
start.forEach(function(s) {
|
||||||
|
if (str.indexOf(s) === 0) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return str.indexOf(start) === 0;
|
return str.indexOf(start) === 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue