Release version 2.0.4
This commit is contained in:
parent
67655d674b
commit
29a9236a6e
7 changed files with 87 additions and 53 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "diff2html",
|
"name": "diff2html",
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"homepage": "https://diff2html.xyz",
|
"homepage": "https://diff2html.xyz",
|
||||||
"description": "Fast Diff to colorized HTML",
|
"description": "Fast Diff to colorized HTML",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
||||||
22
dist/diff2html.css
vendored
22
dist/diff2html.css
vendored
|
|
@ -98,18 +98,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line {
|
.d2h-code-line {
|
||||||
display: block;
|
display: inline-block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin-left: 80px;
|
margin-left: 80px;
|
||||||
|
height: 20px;
|
||||||
|
line-height: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-side-line {
|
.d2h-code-side-line {
|
||||||
display: block;
|
display: inline-block;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
height: 18px;
|
height: 20px;
|
||||||
line-height: 18px;
|
line-height: 20px;
|
||||||
margin-left: 50px;
|
margin-left: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,17 +131,23 @@
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
background-color: #97f295;
|
background-color: #97f295;
|
||||||
border-radius: 0.2em;
|
border-radius: 0.2em;
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line-prefix {
|
.d2h-code-line-prefix {
|
||||||
float: left;
|
display: inline;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
word-wrap: normal;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
.d2h-code-line-ctn {
|
.d2h-code-line-ctn {
|
||||||
|
display: inline;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
word-wrap: normal;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
.line-num1 {
|
.line-num1 {
|
||||||
|
|
@ -353,7 +361,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.selecting-left .d2h-code-line::-moz-selection,
|
.selecting-left .d2h-code-line::-moz-selection,
|
||||||
.selecting-left .d2h-code-line *::-moz-selection
|
.selecting-left .d2h-code-line *::-moz-selection,
|
||||||
.selecting-right td.d2h-code-linenumber::-moz-selection,
|
.selecting-right td.d2h-code-linenumber::-moz-selection,
|
||||||
.selecting-left .d2h-code-side-line::-moz-selection,
|
.selecting-left .d2h-code-side-line::-moz-selection,
|
||||||
.selecting-left .d2h-code-side-line *::-moz-selection,
|
.selecting-left .d2h-code-side-line *::-moz-selection,
|
||||||
|
|
@ -363,7 +371,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.selecting-left .d2h-code-line::selection,
|
.selecting-left .d2h-code-line::selection,
|
||||||
.selecting-left .d2h-code-line *::selection
|
.selecting-left .d2h-code-line *::selection,
|
||||||
.selecting-right td.d2h-code-linenumber::selection,
|
.selecting-right td.d2h-code-linenumber::selection,
|
||||||
.selecting-left .d2h-code-side-line::selection,
|
.selecting-left .d2h-code-side-line::selection,
|
||||||
.selecting-left .d2h-code-side-line *::selection,
|
.selecting-left .d2h-code-side-line *::selection,
|
||||||
|
|
|
||||||
96
dist/diff2html.js
vendored
96
dist/diff2html.js
vendored
|
|
@ -3170,15 +3170,15 @@ process.umask = function() { return 0; };
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
processedOldLines +=
|
processedOldLines +=
|
||||||
that.makeLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
|
that.makeLineHtml(file.isCombined, deleteType, oldLine.oldNumber, oldLine.newNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
processedNewLines +=
|
processedNewLines +=
|
||||||
that.makeLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
|
that.makeLineHtml(file.isCombined, insertType, newLine.oldNumber, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines += processedOldLines + processedNewLines;
|
lines += processedOldLines + processedNewLines;
|
||||||
lines += that._processLines(oldLines.slice(common), newLines.slice(common));
|
lines += that._processLines(file.isCombined, oldLines.slice(common), newLines.slice(common));
|
||||||
});
|
});
|
||||||
|
|
||||||
oldLines = [];
|
oldLines = [];
|
||||||
|
|
@ -3195,9 +3195,9 @@ process.umask = function() { return 0; };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
|
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
|
|
@ -3214,37 +3214,46 @@ process.umask = function() { return 0; };
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype._processLines = function(oldLines, newLines) {
|
LineByLinePrinter.prototype._processLines = function(isCombined, oldLines, newLines) {
|
||||||
var lines = '';
|
var lines = '';
|
||||||
|
|
||||||
for (var i = 0; i < oldLines.length; i++) {
|
for (var i = 0; i < oldLines.length; i++) {
|
||||||
var oldLine = oldLines[i];
|
var oldLine = oldLines[i];
|
||||||
var oldEscapedLine = utils.escape(oldLine.content);
|
var oldEscapedLine = utils.escape(oldLine.content);
|
||||||
lines += this.makeLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
lines += this.makeLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var j = 0; j < newLines.length; j++) {
|
for (var j = 0; j < newLines.length; j++) {
|
||||||
var newLine = newLines[j];
|
var newLine = newLines[j];
|
||||||
var newEscapedLine = utils.escape(newLine.content);
|
var newEscapedLine = utils.escape(newLine.content);
|
||||||
lines += this.makeLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
lines += this.makeLineHtml(isCombined, newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, content, prefix) {
|
LineByLinePrinter.prototype.makeLineHtml = function(isCombined, type, oldNumber, newNumber, content, possiblePrefix) {
|
||||||
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
|
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
|
||||||
oldNumber: utils.valueOrEmpty(oldNumber),
|
oldNumber: utils.valueOrEmpty(oldNumber),
|
||||||
newNumber: utils.valueOrEmpty(newNumber)
|
newNumber: utils.valueOrEmpty(newNumber)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var lineWithoutPrefix = content;
|
||||||
|
var prefix = possiblePrefix;
|
||||||
|
|
||||||
|
if (!prefix) {
|
||||||
|
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
|
||||||
|
prefix = lineWithPrefix.prefix;
|
||||||
|
lineWithoutPrefix = lineWithPrefix.line;
|
||||||
|
}
|
||||||
|
|
||||||
return hoganUtils.render(genericTemplatesPath, 'line',
|
return hoganUtils.render(genericTemplatesPath, 'line',
|
||||||
{
|
{
|
||||||
type: type,
|
type: type,
|
||||||
lineClass: 'd2h-code-linenumber',
|
lineClass: 'd2h-code-linenumber',
|
||||||
contentClass: 'd2h-code-line',
|
contentClass: 'd2h-code-line',
|
||||||
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
|
prefix: prefix,
|
||||||
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
|
content: lineWithoutPrefix,
|
||||||
lineNumber: lineNumberTemplate
|
lineNumber: lineNumberTemplate
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -3277,6 +3286,24 @@ process.umask = function() { return 0; };
|
||||||
function PrinterUtils() {
|
function PrinterUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrinterUtils.prototype.separatePrefix = function(isCombined, line) {
|
||||||
|
var prefix;
|
||||||
|
var lineWithoutPrefix;
|
||||||
|
|
||||||
|
if (isCombined) {
|
||||||
|
prefix = line.substring(0, 2);
|
||||||
|
lineWithoutPrefix = line.substring(2);
|
||||||
|
} else {
|
||||||
|
prefix = line.substring(0, 1);
|
||||||
|
lineWithoutPrefix = line.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'prefix': prefix,
|
||||||
|
'line': lineWithoutPrefix
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
PrinterUtils.prototype.getHtmlId = function(file) {
|
PrinterUtils.prototype.getHtmlId = function(file) {
|
||||||
var hashCode = function(text) {
|
var hashCode = function(text) {
|
||||||
var i, chr, len;
|
var i, chr, len;
|
||||||
|
|
@ -3747,10 +3774,10 @@ process.umask = function() { return 0; };
|
||||||
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
|
||||||
|
|
||||||
fileHtml.left +=
|
fileHtml.left +=
|
||||||
that.generateSingleLineHtml(deleteType, oldLine.oldNumber,
|
that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber,
|
||||||
diff.first.line, diff.first.prefix);
|
diff.first.line, diff.first.prefix);
|
||||||
fileHtml.right +=
|
fileHtml.right +=
|
||||||
that.generateSingleLineHtml(insertType, newLine.newNumber,
|
that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber,
|
||||||
diff.second.line, diff.second.prefix);
|
diff.second.line, diff.second.prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3758,7 +3785,7 @@ process.umask = function() { return 0; };
|
||||||
var oldSlice = oldLines.slice(common);
|
var oldSlice = oldLines.slice(common);
|
||||||
var newSlice = newLines.slice(common);
|
var newSlice = newLines.slice(common);
|
||||||
|
|
||||||
var tmpHtml = that.processLines(oldSlice, newSlice);
|
var tmpHtml = that.processLines(file.isCombined, oldSlice, newSlice);
|
||||||
fileHtml.left += tmpHtml.left;
|
fileHtml.left += tmpHtml.left;
|
||||||
fileHtml.right += tmpHtml.right;
|
fileHtml.right += tmpHtml.right;
|
||||||
}
|
}
|
||||||
|
|
@ -3779,11 +3806,11 @@ process.umask = function() { return 0; };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
if (line.type === diffParser.LINE_TYPE.CONTEXT) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(line.type, line.oldNumber, escapedLine, prefix);
|
fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += that.generateSingleLineHtml(line.type, line.newNumber, escapedLine, prefix);
|
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
} else if (line.type === diffParser.LINE_TYPE.DELETES) {
|
||||||
oldLines.push(line);
|
oldLines.push(line);
|
||||||
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
|
||||||
|
|
@ -3800,7 +3827,7 @@ process.umask = function() { return 0; };
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
SideBySidePrinter.prototype.processLines = function(oldLines, newLines) {
|
SideBySidePrinter.prototype.processLines = function(isCombined, oldLines, newLines) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var fileHtml = {};
|
var fileHtml = {};
|
||||||
fileHtml.left = '';
|
fileHtml.left = '';
|
||||||
|
|
@ -3826,14 +3853,14 @@ process.umask = function() { return 0; };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldLine && newLine) {
|
if (oldLine && newLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
} else if (oldLine) {
|
} else if (oldLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
|
||||||
fileHtml.right += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
} else if (newLine) {
|
} else if (newLine) {
|
||||||
fileHtml.left += that.generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
|
||||||
fileHtml.right += that.generateSingleLineHtml(newLine.type, newLine.newNumber, newContent, newPrefix);
|
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
|
||||||
} else {
|
} else {
|
||||||
console.error('How did it get here?');
|
console.error('How did it get here?');
|
||||||
}
|
}
|
||||||
|
|
@ -3842,14 +3869,23 @@ process.umask = function() { return 0; };
|
||||||
return fileHtml;
|
return fileHtml;
|
||||||
};
|
};
|
||||||
|
|
||||||
SideBySidePrinter.prototype.generateSingleLineHtml = function(type, number, content, prefix) {
|
SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix) {
|
||||||
|
var lineWithoutPrefix = content;
|
||||||
|
var prefix = possiblePrefix;
|
||||||
|
|
||||||
|
if (!prefix) {
|
||||||
|
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
|
||||||
|
prefix = lineWithPrefix.prefix;
|
||||||
|
lineWithoutPrefix = lineWithPrefix.line;
|
||||||
|
}
|
||||||
|
|
||||||
return hoganUtils.render(genericTemplatesPath, 'line',
|
return hoganUtils.render(genericTemplatesPath, 'line',
|
||||||
{
|
{
|
||||||
type: type,
|
type: type,
|
||||||
lineClass: 'd2h-code-side-linenumber',
|
lineClass: 'd2h-code-side-linenumber',
|
||||||
contentClass: 'd2h-code-side-line',
|
contentClass: 'd2h-code-side-line',
|
||||||
prefix: prefix && utils.convertWhiteSpaceToNonBreakingSpace(prefix),
|
prefix: prefix,
|
||||||
content: content && utils.convertWhiteSpaceToNonBreakingSpace(content),
|
content: lineWithoutPrefix,
|
||||||
lineNumber: number
|
lineNumber: number
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -3908,10 +3944,6 @@ module.exports = global.browserTemplates;
|
||||||
function Utils() {
|
function Utils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
|
|
||||||
return str.slice(0).replace(/ /g, ' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
Utils.prototype.escape = function(str) {
|
Utils.prototype.escape = function(str) {
|
||||||
return str.slice(0)
|
return str.slice(0)
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
|
|
|
||||||
2
dist/diff2html.min.css
vendored
2
dist/diff2html.min.css
vendored
File diff suppressed because one or more lines are too long
4
dist/diff2html.min.js
vendored
4
dist/diff2html.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -386,13 +386,7 @@
|
||||||
" </test>\n" +
|
" </test>\n" +
|
||||||
" -->\n" +
|
" -->\n" +
|
||||||
"+\n" +
|
"+\n" +
|
||||||
"+\n" +
|
"+\n";
|
||||||
"--- a/sample.js\n" +
|
|
||||||
"+++ b/sample.js\n" +
|
|
||||||
"@@ -1 +1,2 @@\n" +
|
|
||||||
"-test\n" +
|
|
||||||
"+test1r\n" +
|
|
||||||
"+test2r\n";
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var diff2htmlUi = new Diff2HtmlUI({diff: lineDiffExample});
|
var diff2htmlUi = new Diff2HtmlUI({diff: lineDiffExample});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "diff2html",
|
"name": "diff2html",
|
||||||
"version": "2.0.3",
|
"version": "2.0.4",
|
||||||
"homepage": "https://diff2html.xyz",
|
"homepage": "https://diff2html.xyz",
|
||||||
"description": "Fast Diff to colorized HTML",
|
"description": "Fast Diff to colorized HTML",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue