Skip to content

Commit 64c1e82

Browse files
committed
Prepare for release 2.0.0-beta2
1 parent e64ac60 commit 64c1e82

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta1",
3+
"version": "2.0.0-beta2",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@
7272
/*
7373
* Generates json object from string diff input
7474
*/
75-
Diff2Html.prototype.getJsonFromDiff = function(diffInput) {
76-
return diffParser.generateDiffJson(diffInput);
75+
Diff2Html.prototype.getJsonFromDiff = function(diffInput, config) {
76+
var configOrEmpty = config || {};
77+
return diffParser.generateDiffJson(diffInput, configOrEmpty);
7778
};
7879

7980
/*
@@ -84,7 +85,7 @@
8485

8586
var diffJson = diffInput;
8687
if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') {
87-
diffJson = diffParser.generateDiffJson(diffInput);
88+
diffJson = diffParser.generateDiffJson(diffInput, configOrEmpty);
8889
}
8990

9091
var fileList = '';
@@ -186,7 +187,7 @@
186187

187188
DiffParser.prototype.LINE_TYPE = LINE_TYPE;
188189

189-
DiffParser.prototype.generateDiffJson = function(diffInput) {
190+
DiffParser.prototype.generateDiffJson = function(diffInput, config) {
190191
var files = [];
191192
var currentFile = null;
192193
var currentBlock = null;
@@ -296,11 +297,11 @@
296297
var deletedFileMode = /^deleted file mode (\d{6})/;
297298
var newFileMode = /^new file mode (\d{6})/;
298299

299-
var copyFrom = /^copy from (.+)/;
300-
var copyTo = /^copy to (.+)/;
300+
var copyFrom = /^copy from "?(.+?)"?/;
301+
var copyTo = /^copy to "?(.+?)"?/;
301302

302-
var renameFrom = /^rename from (.+)/;
303-
var renameTo = /^rename to (.+)/;
303+
var renameFrom = /^rename from "?(.+?)"?/;
304+
var renameTo = /^rename to "?(.+?)"?/;
304305

305306
var similarityIndex = /^similarity index (\d+)%/;
306307
var dissimilarityIndex = /^dissimilarity index (\d+)%/;
@@ -323,10 +324,10 @@
323324
var values = [];
324325
if (utils.startsWith(line, 'diff')) {
325326
startFile();
326-
} else if (currentFile && !currentFile.oldName && (values = /^--- [aiwco]\/(.+)$/.exec(line))) {
327+
} else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) {
327328
currentFile.oldName = values[1];
328329
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
329-
} else if (currentFile && !currentFile.newName && (values = /^\+\+\+ [biwco]?\/(.+)$/.exec(line))) {
330+
} else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) {
330331
currentFile.newName = values[1];
331332
currentFile.language = getExtension(currentFile.newName, currentFile.language);
332333
} else if (currentFile && utils.startsWith(line, '@@')) {
@@ -389,6 +390,27 @@
389390
return language;
390391
}
391392

393+
function getSrcFilename(line, cfg) {
394+
var prefixes = ["a\\/", "i\\/", "w\\/", "c\\/", "o\\/"];
395+
396+
if (cfg.srcPrefix) prefixes.push(cfg.srcPrefix);
397+
398+
return _getFilename('---', line, prefixes);
399+
}
400+
401+
function getDstFilename(line, cfg) {
402+
var prefixes = ["b\\/", "i\\/", "w\\/", "c\\/", "o\\/"];
403+
404+
if (cfg.dstPrefix) prefixes.push(cfg.dstPrefix);
405+
406+
return _getFilename('\\+\\+\\+', line, prefixes);
407+
}
408+
409+
function _getFilename(linePrefix, line, prefixes) {
410+
var prefixesStr = prefixes.join("|");
411+
return new RegExp('^' + linePrefix + ' "?(?:' + prefixesStr + ')(.+?)"?$').exec(line);
412+
}
413+
392414
module.exports.DiffParser = new DiffParser();
393415

394416
})();

dist/diff2html.min.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "2.0.0-beta1",
3+
"version": "2.0.0-beta2",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

0 commit comments

Comments
 (0)