Skip to content

Commit 29a9236

Browse files
committed
Release version 2.0.4
1 parent 67655d6 commit 29a9236

File tree

7 files changed

+87
-53
lines changed

7 files changed

+87
-53
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.3",
3+
"version": "2.0.4",
44
"homepage": "https://diff2html.xyz",
55
"description": "Fast Diff to colorized HTML",
66
"keywords": [

dist/diff2html.css

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
display: -ms-flexbox;
4848
display: flex;
4949
-webkit-box-align: center;
50-
-ms-flex-align: center;
51-
align-items: center;
50+
-ms-flex-align: center;
51+
align-items: center;
5252
width: 100%;
5353
font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
5454
font-size: 15px;
@@ -98,18 +98,20 @@
9898
}
9999

100100
.d2h-code-line {
101-
display: block;
101+
display: inline-block;
102102
white-space: nowrap;
103103
padding: 0 10px;
104104
margin-left: 80px;
105+
height: 20px;
106+
line-height: 20px;
105107
}
106108

107109
.d2h-code-side-line {
108-
display: block;
110+
display: inline-block;
109111
white-space: nowrap;
110112
padding: 0 10px;
111-
height: 18px;
112-
line-height: 18px;
113+
height: 20px;
114+
line-height: 20px;
113115
margin-left: 50px;
114116
}
115117

@@ -129,17 +131,23 @@
129131
text-decoration: none;
130132
background-color: #97f295;
131133
border-radius: 0.2em;
134+
text-align: left;
132135
}
133136

134137
.d2h-code-line-prefix {
135-
float: left;
138+
display: inline;
136139
background: none;
137140
padding: 0;
141+
word-wrap: normal;
142+
white-space: pre;
138143
}
139144

140145
.d2h-code-line-ctn {
146+
display: inline;
141147
background: none;
142148
padding: 0;
149+
word-wrap: normal;
150+
white-space: pre;
143151
}
144152

145153
.line-num1 {
@@ -353,7 +361,7 @@
353361
}
354362

355363
.selecting-left .d2h-code-line::-moz-selection,
356-
.selecting-left .d2h-code-line *::-moz-selection
364+
.selecting-left .d2h-code-line *::-moz-selection,
357365
.selecting-right td.d2h-code-linenumber::-moz-selection,
358366
.selecting-left .d2h-code-side-line::-moz-selection,
359367
.selecting-left .d2h-code-side-line *::-moz-selection,
@@ -363,7 +371,7 @@
363371
}
364372

365373
.selecting-left .d2h-code-line::selection,
366-
.selecting-left .d2h-code-line *::selection
374+
.selecting-left .d2h-code-line *::selection,
367375
.selecting-right td.d2h-code-linenumber::selection,
368376
.selecting-left .d2h-code-side-line::selection,
369377
.selecting-left .d2h-code-side-line *::selection,

dist/diff2html.js

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3170,15 +3170,15 @@ process.umask = function() { return 0; };
31703170
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
31713171

31723172
processedOldLines +=
3173-
that.makeLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
3173+
that.makeLineHtml(file.isCombined, deleteType, oldLine.oldNumber, oldLine.newNumber,
31743174
diff.first.line, diff.first.prefix);
31753175
processedNewLines +=
3176-
that.makeLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
3176+
that.makeLineHtml(file.isCombined, insertType, newLine.oldNumber, newLine.newNumber,
31773177
diff.second.line, diff.second.prefix);
31783178
}
31793179

31803180
lines += processedOldLines + processedNewLines;
3181-
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
3181+
lines += that._processLines(file.isCombined, oldLines.slice(common), newLines.slice(common));
31823182
});
31833183

31843184
oldLines = [];
@@ -3195,9 +3195,9 @@ process.umask = function() { return 0; };
31953195
}
31963196

31973197
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
3198-
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
3198+
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
31993199
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
3200-
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
3200+
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
32013201
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
32023202
oldLines.push(line);
32033203
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
@@ -3214,37 +3214,46 @@ process.umask = function() { return 0; };
32143214
}).join('\n');
32153215
};
32163216

3217-
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
3217+
LineByLinePrinter.prototype._processLines = function(isCombined, oldLines, newLines) {
32183218
var lines = '';
32193219

32203220
for (var i = 0; i < oldLines.length; i++) {
32213221
var oldLine = oldLines[i];
32223222
var oldEscapedLine = utils.escape(oldLine.content);
3223-
lines += this.makeLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
3223+
lines += this.makeLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
32243224
}
32253225

32263226
for (var j = 0; j < newLines.length; j++) {
32273227
var newLine = newLines[j];
32283228
var newEscapedLine = utils.escape(newLine.content);
3229-
lines += this.makeLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
3229+
lines += this.makeLineHtml(isCombined, newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
32303230
}
32313231

32323232
return lines;
32333233
};
32343234

3235-
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, content, prefix) {
3235+
LineByLinePrinter.prototype.makeLineHtml = function(isCombined, type, oldNumber, newNumber, content, possiblePrefix) {
32363236
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
32373237
oldNumber: utils.valueOrEmpty(oldNumber),
32383238
newNumber: utils.valueOrEmpty(newNumber)
32393239
});
32403240

3241+
var lineWithoutPrefix = content;
3242+
var prefix = possiblePrefix;
3243+
3244+
if (!prefix) {
3245+
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
3246+
prefix = lineWithPrefix.prefix;
3247+
lineWithoutPrefix = lineWithPrefix.line;
3248+
}
3249+
32413250
return hoganUtils.render(genericTemplatesPath, 'line',
32423251
{
32433252
type: type,
32443253
lineClass: 'd2h-code-linenumber',
32453254
contentClass: 'd2h-code-line',
3246-
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
3247-
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
3255+
prefix: prefix,
3256+
content: lineWithoutPrefix,
32483257
lineNumber: lineNumberTemplate
32493258
});
32503259
};
@@ -3277,6 +3286,24 @@ process.umask = function() { return 0; };
32773286
function PrinterUtils() {
32783287
}
32793288

3289+
PrinterUtils.prototype.separatePrefix = function(isCombined, line) {
3290+
var prefix;
3291+
var lineWithoutPrefix;
3292+
3293+
if (isCombined) {
3294+
prefix = line.substring(0, 2);
3295+
lineWithoutPrefix = line.substring(2);
3296+
} else {
3297+
prefix = line.substring(0, 1);
3298+
lineWithoutPrefix = line.substring(1);
3299+
}
3300+
3301+
return {
3302+
'prefix': prefix,
3303+
'line': lineWithoutPrefix
3304+
};
3305+
};
3306+
32803307
PrinterUtils.prototype.getHtmlId = function(file) {
32813308
var hashCode = function(text) {
32823309
var i, chr, len;
@@ -3747,18 +3774,18 @@ process.umask = function() { return 0; };
37473774
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
37483775

37493776
fileHtml.left +=
3750-
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
3777+
that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber,
37513778
diff.first.line, diff.first.prefix);
37523779
fileHtml.right +=
3753-
that.generateSingleLineHtml(insertType, newLine.newNumber,
3780+
that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber,
37543781
diff.second.line, diff.second.prefix);
37553782
}
37563783

37573784
if (max > common) {
37583785
var oldSlice = oldLines.slice(common);
37593786
var newSlice = newLines.slice(common);
37603787

3761-
var tmpHtml = that.processLines(oldSlice, newSlice);
3788+
var tmpHtml = that.processLines(file.isCombined, oldSlice, newSlice);
37623789
fileHtml.left += tmpHtml.left;
37633790
fileHtml.right += tmpHtml.right;
37643791
}
@@ -3779,11 +3806,11 @@ process.umask = function() { return 0; };
37793806
}
37803807

37813808
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
3782-
fileHtml.left += that.generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
3783-
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
3809+
fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix);
3810+
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
37843811
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
3785-
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
3786-
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
3812+
fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
3813+
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
37873814
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
37883815
oldLines.push(line);
37893816
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
@@ -3800,7 +3827,7 @@ process.umask = function() { return 0; };
38003827
return fileHtml;
38013828
};
38023829

3803-
SideBySidePrinter.prototype.processLines = function(oldLines, newLines) {
3830+
SideBySidePrinter.prototype.processLines = function(isCombined, oldLines, newLines) {
38043831
var that = this;
38053832
var fileHtml = {};
38063833
fileHtml.left = '';
@@ -3826,14 +3853,14 @@ process.umask = function() { return 0; };
38263853
}
38273854

38283855
if (oldLine && newLine) {
3829-
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
3830-
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
3856+
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
3857+
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
38313858
} else if (oldLine) {
3832-
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
3833-
fileHtml.right += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
3859+
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
3860+
fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
38343861
} else if (newLine) {
3835-
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
3836-
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
3862+
fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
3863+
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
38373864
} else {
38383865
console.error('How did it get here?');
38393866
}
@@ -3842,14 +3869,23 @@ process.umask = function() { return 0; };
38423869
return fileHtml;
38433870
};
38443871

3845-
SideBySidePrinter.prototype.generateSingleLineHtml = function(type, number, content, prefix) {
3872+
SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix) {
3873+
var lineWithoutPrefix = content;
3874+
var prefix = possiblePrefix;
3875+
3876+
if (!prefix) {
3877+
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
3878+
prefix = lineWithPrefix.prefix;
3879+
lineWithoutPrefix = lineWithPrefix.line;
3880+
}
3881+
38463882
return hoganUtils.render(genericTemplatesPath, 'line',
38473883
{
38483884
type: type,
38493885
lineClass: 'd2h-code-side-linenumber',
38503886
contentClass: 'd2h-code-side-line',
3851-
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
3852-
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
3887+
prefix: prefix,
3888+
content: lineWithoutPrefix,
38533889
lineNumber: number
38543890
});
38553891
};
@@ -3908,10 +3944,6 @@ module.exports = global.browserTemplates;
39083944
function Utils() {
39093945
}
39103946

3911-
Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
3912-
return str.slice(0).replace(/ /g, '&nbsp;');
3913-
};
3914-
39153947
Utils.prototype.escape = function(str) {
39163948
return str.slice(0)
39173949
.replace(/&/g, '&amp;')

0 commit comments

Comments
 (0)