Skip to content

Commit ef4a4e1

Browse files
committed
Prepare for release 2.0.0-beta18
1 parent 2b05eaf commit ef4a4e1

File tree

5 files changed

+74
-21
lines changed

5 files changed

+74
-21
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
[![npm](https://img.shields.io/npm/dm/diff2html.svg)](https://www.npmjs.com/package/diff2html)
1414
[![Gitter](https://badges.gitter.im/rtfpessoa/diff2html.svg)](https://gitter.im/rtfpessoa/diff2html?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1515

16-
diff2html generates pretty HTML diffs from git diff output.
16+
diff2html generates pretty HTML diffs from git or unified diff output.
1717

1818
[![NPM](https://nodei.co/npm/diff2html.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/diff2html/)
1919

2020
## Features
2121

22+
* Supports git and unified diffs
23+
2224
* Line by line and Side by side diff
2325

2426
* New and old line numbers

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-beta17",
3+
"version": "2.0.0-beta18",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.js

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,32 +2333,30 @@ process.umask = function() { return 0; };
23332333
var oldLine2 = null; // Used for combined diff
23342334
var newLine = null;
23352335

2336+
/* Add previous block(if exists) before start a new file */
23362337
var saveBlock = function() {
2337-
2338-
/* Add previous block(if exists) before start a new file */
23392338
if (currentBlock) {
23402339
currentFile.blocks.push(currentBlock);
23412340
currentBlock = null;
23422341
}
23432342
};
23442343

2344+
/*
2345+
* Add previous file(if exists) before start a new one
2346+
* if it has name (to avoid binary files errors)
2347+
*/
23452348
var saveFile = function() {
2346-
2347-
/*
2348-
* Add previous file(if exists) before start a new one
2349-
* if it has name (to avoid binary files errors)
2350-
*/
23512349
if (currentFile && currentFile.newName) {
23522350
files.push(currentFile);
23532351
currentFile = null;
23542352
}
23552353
};
23562354

2355+
/* Create file structure */
23572356
var startFile = function() {
23582357
saveBlock();
23592358
saveFile();
23602359

2361-
/* Create file structure */
23622360
currentFile = {};
23632361
currentFile.blocks = [];
23642362
currentFile.deletedLines = 0;
@@ -2479,18 +2477,72 @@ process.umask = function() { return 0; };
24792477
return;
24802478
}
24812479

2482-
var values = [];
2483-
if (utils.startsWith(line, 'diff')) {
2480+
if (
2481+
utils.startsWith(line, 'diff') || // Git diffs always start with diff
2482+
!currentFile || // If we do not have a file yet, we should crete one
2483+
(
2484+
currentFile && // If we already have some file in progress and
2485+
(
2486+
currentFile.oldName && utils.startsWith(line, '---') || // Either we reached a old file identification line
2487+
currentFile.newName && utils.startsWith(line, '+++') // Or we reached a new file identification line
2488+
)
2489+
)
2490+
) {
24842491
startFile();
2485-
} else if (currentFile && !currentFile.oldName && (values = getSrcFilename(line, config))) {
2492+
}
2493+
2494+
var values;
2495+
2496+
/*
2497+
* --- Date Timestamp[FractionalSeconds] TimeZone
2498+
* --- 2002-02-21 23:30:39.942229878 -0800
2499+
*/
2500+
if (currentFile && !currentFile.oldName &&
2501+
utils.startsWith(line, '---') && (values = getSrcFilename(line, config))) {
24862502
currentFile.oldName = values;
24872503
currentFile.language = getExtension(currentFile.oldName, currentFile.language);
2488-
} else if (currentFile && !currentFile.newName && (values = getDstFilename(line, config))) {
2504+
return;
2505+
}
2506+
2507+
/*
2508+
* +++ Date Timestamp[FractionalSeconds] TimeZone
2509+
* +++ 2002-02-21 23:30:39.942229878 -0800
2510+
*/
2511+
if (currentFile && !currentFile.newName &&
2512+
utils.startsWith(line, '+++') && (values = getDstFilename(line, config))) {
24892513
currentFile.newName = values;
24902514
currentFile.language = getExtension(currentFile.newName, currentFile.language);
2491-
} else if (currentFile && utils.startsWith(line, '@@')) {
2515+
return;
2516+
}
2517+
2518+
if (currentFile && utils.startsWith(line, '@')) {
24922519
startBlock(line);
2493-
} else if ((values = oldMode.exec(line))) {
2520+
return;
2521+
}
2522+
2523+
/*
2524+
* There are three types of diff lines. These lines are defined by the way they start.
2525+
* 1. New line starts with: +
2526+
* 2. Old line starts with: -
2527+
* 3. Context line starts with: <SPACE>
2528+
*/
2529+
if (currentBlock && (utils.startsWith(line, '+') || utils.startsWith(line, '-') || utils.startsWith(line, ' '))) {
2530+
createLine(line);
2531+
return;
2532+
}
2533+
2534+
if (
2535+
(currentFile && currentFile.blocks.length) ||
2536+
(currentBlock && currentBlock.lines.length)
2537+
) {
2538+
startFile();
2539+
}
2540+
2541+
/*
2542+
* Git diffs provide more information regarding files modes, renames, copies,
2543+
* commits between changes and similarity indexes
2544+
*/
2545+
if ((values = oldMode.exec(line))) {
24942546
currentFile.oldMode = values[1];
24952547
} else if ((values = newMode.exec(line))) {
24962548
currentFile.newMode = values[1];
@@ -2532,8 +2584,6 @@ process.umask = function() { return 0; };
25322584
} else if ((values = combinedDeletedFile.exec(line))) {
25332585
currentFile.deletedFileMode = values[1];
25342586
currentFile.isDeleted = true;
2535-
} else if (currentBlock) {
2536-
createLine(line);
25372587
}
25382588
});
25392589

dist/diff2html.min.js

Lines changed: 3 additions & 2 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-beta17",
3+
"version": "2.0.0-beta18",
44
"homepage": "http://rtfpessoa.github.io/diff2html/",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

0 commit comments

Comments
 (0)