Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

diff2html

Package Overview
Dependencies
Maintainers
1
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff2html - npm Package Compare versions

Comparing version 0.2.6 to 1.0.0-1

57

package.json
{
"name": "diff2html",
"version": "0.2.6",
"name": "diff2html",
"version": "1.0.0-1",
"homepage": "http://rtfpessoa.github.io/diff2html/",
"description": "Fast Diff to colorized HTML",
"keywords": [
"git",
"diff",
"pretty",
"side",
"line",
"side-by-side",
"line-by-line",
"character",
"highlight",
"pretty",
"color",
"html",
"diff2html",
"difftohtml",
"colorized"
],
"git",
"diff",
"pretty",
"side",
"line",
"side-by-side",
"line-by-line",
"character",
"highlight",
"pretty",
"color",
"html",
"diff2html",
"difftohtml",
"colorized"
],
"author": {
"name": "Rodrigo Fernandes",
"name": "Rodrigo Fernandes",
"email": "rtfrodrigo@gmail.com"
},
"repository": {

@@ -33,36 +31,21 @@ "type": "git",

},
"bugs": {
"url": "https://www.github.com/rtfpessoa/diff2html/issues"
},
"engines": {
"node": ">=0.10"
"node": ">=0.10"
},
"preferGlobal": "true",
"scripts": {
"test": ""
},
"bin": {
"diff2html-lib": "./bin/diff2html"
},
"main": "./src/diff2html.js",
"dependencies": {
"diff": "1.4.0"
},
"devDependencies": {},
"license": "MIT",
"files": [
"bin",
"lib",
"src"
]
}

@@ -62,3 +62,2 @@ # Diff to Html by [rtfpessoa](https://github.com/rtfpessoa)

If your favourite language is not included in the default package also add its javascript highlight file.
jQuery is optional, just using it to help managing the highlight.

@@ -70,3 +69,2 @@ ```html

<!-- Javascripts -->
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>

@@ -73,0 +71,0 @@ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/languages/scala.min.js"></script>

@@ -8,11 +8,11 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
var utils = require("./utils.js").Utils;
var utils = require('./utils.js').Utils;
var LINE_TYPE = {
INSERTS: "d2h-ins",
DELETES: "d2h-del",
CONTEXT: "d2h-cntx",
INFO: "d2h-info"
INSERTS: 'd2h-ins',
DELETES: 'd2h-del',
CONTEXT: 'd2h-cntx',
INFO: 'd2h-info'
};

@@ -25,11 +25,11 @@

DiffParser.prototype.generateDiffJson = function (diffInput) {
var files = [],
currentFile = null,
currentBlock = null,
oldLine = null,
newLine = null;
DiffParser.prototype.generateDiffJson = function(diffInput) {
var files = [];
var currentFile = null;
var currentBlock = null;
var oldLine = null;
var newLine = null;
var saveBlock = function () {
/* add previous block(if exists) before start a new file */
var saveBlock = function() {
/* Add previous block(if exists) before start a new file */
if (currentBlock) {

@@ -41,5 +41,5 @@ currentFile.blocks.push(currentBlock);

var saveFile = function () {
var saveFile = function() {
/*
* add previous file(if exists) before start a new one
* Add previous file(if exists) before start a new one
* if it has name (to avoid binary files errors)

@@ -53,7 +53,7 @@ */

var startFile = function () {
var startFile = function() {
saveBlock();
saveFile();
/* create file structure */
/* Create file structure */
currentFile = {};

@@ -65,3 +65,3 @@ currentFile.blocks = [];

var startBlock = function (line) {
var startBlock = function(line) {
saveBlock();

@@ -83,3 +83,3 @@

/* create block metadata */
/* Create block metadata */
currentBlock = {};

@@ -92,8 +92,11 @@ currentBlock.lines = [];

var createLine = function (line) {
var createLine = function(line) {
var currentLine = {};
currentLine.content = line;
/* fill the line data */
if (utils.startsWith(line, "+") || utils.startsWith(line, " +")) {
var newLinePrefixes = !currentFile.isCombined ? ['+'] : ['+', ' +'];
var delLinePrefixes = !currentFile.isCombined ? ['-'] : ['-', ' -'];
/* Fill the line data */
if (utils.startsWith(line, newLinePrefixes)) {
currentFile.addedLines++;

@@ -107,3 +110,3 @@

} else if (utils.startsWith(line, "-") || utils.startsWith(line, " -")) {
} else if (utils.startsWith(line, delLinePrefixes)) {
currentFile.deletedLines++;

@@ -126,9 +129,8 @@

var diffLines = diffInput.split("\n");
diffLines.forEach(function (line) {
var diffLines = diffInput.split('\n');
diffLines.forEach(function(line) {
// Unmerged paths, and possibly other non-diffable files
// https://github.com/scottgonzalez/pretty-diff/issues/11
// Also, remove some useless lines
if (!line || utils.startsWith(line, "*")) {
//|| utils.startsWith(line, "new") || utils.startsWith(line, "index")
if (!line || utils.startsWith(line, '*')) {
return;

@@ -160,3 +162,3 @@ }

var values = [];
if (utils.startsWith(line, "diff")) {
if (utils.startsWith(line, 'diff')) {
startFile();

@@ -169,3 +171,3 @@ } else if (currentFile && !currentFile.oldName && (values = /^--- a\/(\S+).*$/.exec(line))) {

currentFile.language = getExtension(currentFile.newName, currentFile.language);
} else if (currentFile && utils.startsWith(line, "@@")) {
} else if (currentFile && utils.startsWith(line, '@@')) {
startBlock(line);

@@ -222,15 +224,12 @@ } else if ((values = oldMode.exec(line))) {

function getExtension(filename, language) {
var nameSplit = filename.split(".");
if (nameSplit.length > 1) return nameSplit[nameSplit.length - 1];
else return language;
var nameSplit = filename.split('.');
if (nameSplit.length > 1) {
return nameSplit[nameSplit.length - 1];
} else {
return language;
}
}
// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["DiffParser"] = new DiffParser();
module.exports['DiffParser'] = new DiffParser();
})(this);

@@ -8,6 +8,6 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
var diffParser = require("./diff-parser.js").DiffParser;
var htmlPrinter = require("./html-printer.js").HtmlPrinter;
var diffParser = require('./diff-parser.js').DiffParser;
var htmlPrinter = require('./html-printer.js').HtmlPrinter;

@@ -29,3 +29,3 @@ function Diff2Html() {

*/
Diff2Html.prototype.getPrettyHtmlFromDiff = function (diffInput, config) {
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
var diffJson = diffParser.generateDiffJson(diffInput);

@@ -39,3 +39,3 @@ var configOrEmpty = config || {};

*/
Diff2Html.prototype.getJsonFromDiff = function (diffInput) {
Diff2Html.prototype.getJsonFromDiff = function(diffInput) {
return diffParser.generateDiffJson(diffInput);

@@ -47,3 +47,3 @@ };

*/
Diff2Html.prototype.getPrettyHtmlFromJson = function (diffJson, config) {
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
var configOrEmpty = config || {};

@@ -56,3 +56,3 @@ return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);

*/
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput, config) {
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
var diffJson = diffParser.generateDiffJson(diffInput);

@@ -67,3 +67,3 @@

*/
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function (diffJson, config) {
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
var configOrEmpty = config || {};

@@ -73,10 +73,8 @@ return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);

// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["Diff2Html"] = new Diff2Html();
var diffName = 'Diff2Html';
var diffObject = new Diff2Html();
module.exports[diffName] = diffObject;
// Expose diff2html in the browser
global[diffName] = diffObject;
})(this);

@@ -8,6 +8,6 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
var lineByLinePrinter = require("./line-by-line-printer.js").LineByLinePrinter;
var sideBySidePrinter = require("./side-by-side-printer.js").SideBySidePrinter;
var lineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
var sideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;

@@ -21,10 +21,4 @@ function HtmlPrinter() {

// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["HtmlPrinter"] = new HtmlPrinter();
module.exports['HtmlPrinter'] = new HtmlPrinter();
})(this);

@@ -8,7 +8,7 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
var diffParser = require("./diff-parser.js").DiffParser;
var printerUtils = require("./printer-utils.js").PrinterUtils;
var utils = require("./utils.js").Utils;
var diffParser = require('./diff-parser.js').DiffParser;
var printerUtils = require('./printer-utils.js').PrinterUtils;
var utils = require('./utils.js').Utils;

@@ -18,44 +18,49 @@ function LineByLinePrinter() {

LineByLinePrinter.prototype.generateLineByLineJsonHtml = function (diffFiles, config) {
return "<div class=\"d2h-wrapper\">\n" +
diffFiles.map(function (file) {
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles, config) {
return '<div class="d2h-wrapper">\n' +
diffFiles.map(function(file) {
var diffs;
if (file.blocks.length) diffs = generateFileHtml(file, config);
else diffs = generateEmptyDiff();
if (file.blocks.length) {
diffs = generateFileHtml(file, config);
} else {
diffs = generateEmptyDiff();
}
return "<div class=\"d2h-file-wrapper\" data-lang=\"" + file.language + "\">\n" +
" <div class=\"d2h-file-header\">\n" +
" <div class=\"d2h-file-stats\">\n" +
" <span class=\"d2h-lines-added\">+" + file.addedLines + "</span>\n" +
" <span class=\"d2h-lines-deleted\">-" + file.deletedLines + "</span>\n" +
" </div>\n" +
" <div class=\"d2h-file-name\">" + printerUtils.getDiffName(file) + "</div>\n" +
" </div>\n" +
" <div class=\"d2h-file-diff\">\n" +
" <div class=\"d2h-code-wrapper\">\n" +
" <table class=\"d2h-diff-table\">\n" +
" <tbody class=\"d2h-diff-tbody\">\n" +
" " + diffs +
" </tbody>\n" +
" </table>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n";
}).join("\n") +
"</div>\n";
return '<div class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
' <div class="d2h-file-header">\n' +
' <div class="d2h-file-stats">\n' +
' <span class="d2h-lines-added">+' + file.addedLines + '</span>\n' +
' <span class="d2h-lines-deleted">-' + file.deletedLines + '</span>\n' +
' </div>\n' +
' <div class="d2h-file-name">' + printerUtils.getDiffName(file) + '</div>\n' +
' </div>\n' +
' <div class="d2h-file-diff">\n' +
' <div class="d2h-code-wrapper">\n' +
' <table class="d2h-diff-table">\n' +
' <tbody class="d2h-diff-tbody">\n' +
' ' + diffs +
' </tbody>\n' +
' </table>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n';
}).join('\n') +
'</div>\n';
};
function generateFileHtml(file, config) {
return file.blocks.map(function (block) {
return file.blocks.map(function(block) {
var lines = "<tr>\n" +
" <td class=\"d2h-code-linenumber " + diffParser.LINE_TYPE.INFO + "\"></td>\n" +
" <td class=\"" + diffParser.LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-line " + diffParser.LINE_TYPE.INFO + "\">" + utils.escape(block.header) + "</div>" +
" </td>\n" +
"</tr>\n";
var lines = '<tr>\n' +
' <td class="d2h-code-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' + utils.escape(block.header) + '</div>' +
' </td>\n' +
'</tr>\n';
var oldLines = [], newLines = [];
var processedOldLines = [], processedNewLines = [];
var oldLines = [];
var newLines = [];
var processedOldLines = [];
var processedNewLines = [];

@@ -86,4 +91,8 @@ for (var i = 0; i < block.lines.length; i++) {

processedOldLines += generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, diff.first.line, diff.first.prefix);
processedNewLines += generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, diff.second.line, diff.second.prefix);
processedOldLines +=
generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber,
diff.first.line, diff.first.prefix);
processedNewLines +=
generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber,
diff.second.line, diff.second.prefix);
}

@@ -107,7 +116,7 @@

return lines;
}).join("\n");
}).join('\n');
}
function processLines(oldLines, newLines) {
var lines = "";
var lines = '';

@@ -130,37 +139,35 @@ for (j = 0; j < oldLines.length; j++) {

function generateLineHtml(type, oldNumber, newNumber, content, prefix) {
var htmlPrefix = "";
if (prefix) htmlPrefix = "<span class=\"d2h-code-line-prefix\">" + prefix + "</span>";
var htmlPrefix = '';
if (prefix) {
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
}
var htmlContent = "";
if (content) htmlContent = "<span class=\"d2h-code-line-ctn\">" + content + "</span>";
var htmlContent = '';
if (content) {
htmlContent = '<span class="d2h-code-line-ctn">' + content + '</span>';
}
return "<tr>\n" +
" <td class=\"d2h-code-linenumber " + type + "\">" +
" <div class=\"line-num1\">" + utils.valueOrEmpty(oldNumber) + "</div>" +
" <div class=\"line-num2\">" + utils.valueOrEmpty(newNumber) + "</div>" +
" </td>\n" +
" <td class=\"" + type + "\">" +
" <div class=\"d2h-code-line " + type + "\">" + htmlPrefix + htmlContent + "</div>" +
" </td>\n" +
"</tr>\n";
return '<tr>\n' +
' <td class="d2h-code-linenumber ' + type + '">' +
' <div class="line-num1">' + utils.valueOrEmpty(oldNumber) + '</div>' +
' <div class="line-num2">' + utils.valueOrEmpty(newNumber) + '</div>' +
' </td>\n' +
' <td class="' + type + '">' +
' <div class="d2h-code-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
' </td>\n' +
'</tr>\n';
}
function generateEmptyDiff() {
return "<tr>\n" +
" <td class=\"" + diffParser.LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-line " + diffParser.LINE_TYPE.INFO + "\">" +
"File without changes" +
" </div>" +
" </td>\n" +
"</tr>\n";
return '<tr>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-line ' + diffParser.LINE_TYPE.INFO + '">' +
'File without changes' +
' </div>' +
' </td>\n' +
'</tr>\n';
}
// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["LineByLinePrinter"] = new LineByLinePrinter();
module.exports['LineByLinePrinter'] = new LineByLinePrinter();
})(this);

@@ -8,7 +8,6 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
// dirty hack for browser compatibility
var jsDiff = (typeof JsDiff !== "undefined" && JsDiff) || require("diff");
var utils = require("./utils.js").Utils;
var jsDiff = require('diff');
var utils = require('./utils.js').Utils;

@@ -18,3 +17,3 @@ function PrinterUtils() {

PrinterUtils.prototype.getDiffName = function (file) {
PrinterUtils.prototype.getDiffName = function(file) {
var oldFilename = file.oldName;

@@ -26,3 +25,3 @@ var newFilename = file.newName;

&& !isDeletedName(newFilename)) {
return oldFilename + " -> " + newFilename;
return oldFilename + ' -> ' + newFilename;
} else if (newFilename && !isDeletedName(newFilename)) {

@@ -33,7 +32,7 @@ return newFilename;

} else {
return "Unknown filename";
return 'Unknown filename';
}
};
PrinterUtils.prototype.diffHighlight = function (diffLine1, diffLine2, config) {
PrinterUtils.prototype.diffHighlight = function(diffLine1, diffLine2, config) {
var lineStart1, lineStart2;

@@ -43,3 +42,5 @@

if (config.isCombined) prefixSize = 2;
if (config.isCombined) {
prefixSize = 2;
}

@@ -53,13 +54,19 @@ lineStart1 = diffLine1.substr(0, prefixSize);

var diff;
if (config.charByChar) diff = jsDiff.diffChars(diffLine1, diffLine2);
else diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2);
if (config.charByChar) {
diff = jsDiff.diffChars(diffLine1, diffLine2);
} else {
diff = jsDiff.diffWordsWithSpace(diffLine1, diffLine2);
}
var highlightedLine = "";
var highlightedLine = '';
diff.forEach(function (part) {
diff.forEach(function(part) {
var elemType = part.added ? 'ins' : part.removed ? 'del' : null;
var escapedValue = utils.escape(part.value);
if (elemType !== null) highlightedLine += "<" + elemType + ">" + escapedValue + "</" + elemType + ">";
else highlightedLine += escapedValue;
if (elemType !== null) {
highlightedLine += '<' + elemType + '>' + escapedValue + '</' + elemType + '>';
} else {
highlightedLine += escapedValue;
}
});

@@ -80,21 +87,15 @@

function isDeletedName(name) {
return name === "dev/null";
return name === 'dev/null';
}
function removeIns(line) {
return line.replace(/(<ins>((.|\n)*?)<\/ins>)/g, "");
return line.replace(/(<ins>((.|\n)*?)<\/ins>)/g, '');
}
function removeDel(line) {
return line.replace(/(<del>((.|\n)*?)<\/del>)/g, "");
return line.replace(/(<del>((.|\n)*?)<\/del>)/g, '');
}
// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["PrinterUtils"] = new PrinterUtils();
module.exports['PrinterUtils'] = new PrinterUtils();
})(this);

@@ -8,7 +8,7 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {
var diffParser = require("./diff-parser.js").DiffParser;
var printerUtils = require("./printer-utils.js").PrinterUtils;
var utils = require("./utils.js").Utils;
var diffParser = require('./diff-parser.js').DiffParser;
var printerUtils = require('./printer-utils.js').PrinterUtils;
var utils = require('./utils.js').Utils;

@@ -18,41 +18,44 @@ function SideBySidePrinter() {

SideBySidePrinter.prototype.generateSideBySideJsonHtml = function (diffFiles, config) {
return "<div class=\"d2h-wrapper\">\n" +
diffFiles.map(function (file) {
SideBySidePrinter.prototype.generateSideBySideJsonHtml = function(diffFiles, config) {
return '<div class="d2h-wrapper">\n' +
diffFiles.map(function(file) {
var diffs;
if (file.blocks.length) diffs = generateSideBySideFileHtml(file, config);
else diffs = generateEmptyDiff();
if (file.blocks.length) {
diffs = generateSideBySideFileHtml(file, config);
} else {
diffs = generateEmptyDiff();
}
return "<div class=\"d2h-file-wrapper\" data-lang=\"" + file.language + "\">\n" +
" <div class=\"d2h-file-header\">\n" +
" <div class=\"d2h-file-stats\">\n" +
" <span class=\"d2h-lines-added\">+" + file.addedLines + "</span>\n" +
" <span class=\"d2h-lines-deleted\">-" + file.deletedLines + "</span>\n" +
" </div>\n" +
" <div class=\"d2h-file-name\">" + printerUtils.getDiffName(file) + "</div>\n" +
" </div>\n" +
" <div class=\"d2h-files-diff\">\n" +
" <div class=\"d2h-file-side-diff\">\n" +
" <div class=\"d2h-code-wrapper\">\n" +
" <table class=\"d2h-diff-table\">\n" +
" <tbody class=\"d2h-diff-tbody\">\n" +
" " + diffs.left +
" </tbody>\n" +
" </table>\n" +
" </div>\n" +
" </div>\n" +
" <div class=\"d2h-file-side-diff\">\n" +
" <div class=\"d2h-code-wrapper\">\n" +
" <table class=\"d2h-diff-table\">\n" +
" <tbody class=\"d2h-diff-tbody\">\n" +
" " + diffs.right +
" </tbody>\n" +
" </table>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n" +
" </div>\n";
}).join("\n") +
"</div>\n";
return '<div class="d2h-file-wrapper" data-lang="' + file.language + '">\n' +
' <div class="d2h-file-header">\n' +
' <div class="d2h-file-stats">\n' +
' <span class="d2h-lines-added">+' + file.addedLines + '</span>\n' +
' <span class="d2h-lines-deleted">-' + file.deletedLines + '</span>\n' +
' </div>\n' +
' <div class="d2h-file-name">' + printerUtils.getDiffName(file) + '</div>\n' +
' </div>\n' +
' <div class="d2h-files-diff">\n' +
' <div class="d2h-file-side-diff">\n' +
' <div class="d2h-code-wrapper">\n' +
' <table class="d2h-diff-table">\n' +
' <tbody class="d2h-diff-tbody">\n' +
' ' + diffs.left +
' </tbody>\n' +
' </table>\n' +
' </div>\n' +
' </div>\n' +
' <div class="d2h-file-side-diff">\n' +
' <div class="d2h-code-wrapper">\n' +
' <table class="d2h-diff-table">\n' +
' <tbody class="d2h-diff-tbody">\n' +
' ' + diffs.right +
' </tbody>\n' +
' </table>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n' +
' </div>\n';
}).join('\n') +
'</div>\n';
};

@@ -62,23 +65,26 @@

var fileHtml = {};
fileHtml.left = "";
fileHtml.right = "";
fileHtml.left = '';
fileHtml.right = '';
file.blocks.forEach(function (block) {
file.blocks.forEach(function(block) {
fileHtml.left += "<tr>\n" +
" <td class=\"d2h-code-side-linenumber " + diffParser.LINE_TYPE.INFO + "\"></td>\n" +
" <td class=\"" + diffParser.LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-side-line " + diffParser.LINE_TYPE.INFO + "\">" + utils.escape(block.header) + "</div>" +
" </td>\n" +
"</tr>\n";
fileHtml.left += '<tr>\n' +
' <td class="d2h-code-side-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-side-line ' + diffParser.LINE_TYPE.INFO + '">' +
' ' + utils.escape(block.header) +
' </div>' +
' </td>\n' +
'</tr>\n';
fileHtml.right += "<tr>\n" +
" <td class=\"d2h-code-side-linenumber " + diffParser.LINE_TYPE.INFO + "\"></td>\n" +
" <td class=\"" + diffParser.LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-side-line " + diffParser.LINE_TYPE.INFO + "\"></div>" +
" </td>\n" +
"</tr>\n";
fileHtml.right += '<tr>\n' +
' <td class="d2h-code-side-linenumber ' + diffParser.LINE_TYPE.INFO + '"></td>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-side-line ' + diffParser.LINE_TYPE.INFO + '"></div>' +
' </td>\n' +
'</tr>\n';
var oldLines = [], newLines = [];
var tmpHtml = "";
var oldLines = [];
var newLines = [];
var tmpHtml = '';

@@ -93,3 +99,3 @@ for (var i = 0; i < block.lines.length; i++) {

} else if (line.type == diffParser.LINE_TYPE.INSERTS && !oldLines.length && !newLines.length) {
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", "");
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, escapedLine);

@@ -113,4 +119,8 @@ } else if (line.type == diffParser.LINE_TYPE.DELETES && !newLines.length) {

fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, diff.first.line, diff.first.prefix);
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, diff.second.line, diff.second.prefix);
fileHtml.left +=
generateSingleLineHtml(oldLine.type, oldLine.oldNumber,
diff.first.line, diff.first.prefix);
fileHtml.right +=
generateSingleLineHtml(newLine.type, newLine.newNumber,
diff.second.line, diff.second.prefix);
}

@@ -139,4 +149,4 @@ } else {

var fileHtml = {};
fileHtml.left = "";
fileHtml.right = "";
fileHtml.left = '';
fileHtml.right = '';

@@ -153,8 +163,8 @@ var maxLinesNumber = Math.max(oldLines.length, newLines.length);

fileHtml.left += generateSingleLineHtml(oldLine.type, oldLine.oldNumber, utils.escape(oldLine.content));
fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", "");
fileHtml.right += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
} else if (newLine) {
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, "", "", "");
fileHtml.left += generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT, '', '', '');
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, utils.escape(newLine.content));
} else {
console.error("How did it get here?");
console.error('How did it get here?');
}

@@ -167,14 +177,18 @@ }

function generateSingleLineHtml(type, number, content, prefix) {
var htmlPrefix = "";
if (prefix) htmlPrefix = "<span class=\"d2h-code-line-prefix\">" + prefix + "</span>";
var htmlPrefix = '';
if (prefix) {
htmlPrefix = '<span class="d2h-code-line-prefix">' + prefix + '</span>';
}
var htmlContent = "";
if (content) htmlContent = "<span class=\"d2h-code-line-ctn\">" + content + "</span>";
var htmlContent = '';
if (content) {
htmlContent = '<span class="d2h-code-line-ctn">' + content + '</span>';
}
return "<tr>\n" +
" <td class=\"d2h-code-side-linenumber " + type + "\">" + number + "</td>\n" +
" <td class=\"" + type + "\">" +
" <div class=\"d2h-code-side-line " + type + "\">" + htmlPrefix + htmlContent + "</div>" +
" </td>\n" +
" </tr>\n";
return '<tr>\n' +
' <td class="d2h-code-side-linenumber ' + type + '">' + number + '</td>\n' +
' <td class="' + type + '">' +
' <div class="d2h-code-side-line ' + type + '">' + htmlPrefix + htmlContent + '</div>' +
' </td>\n' +
' </tr>\n';
}

@@ -184,11 +198,11 @@

var fileHtml = {};
fileHtml.right = "";
fileHtml.right = '';
fileHtml.left = "<tr>\n" +
" <td class=\"" + diffParser.LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-side-line " + diffParser.LINE_TYPE.INFO + "\">" +
"File without changes" +
" </div>" +
" </td>\n" +
"</tr>\n";
fileHtml.left = '<tr>\n' +
' <td class="' + diffParser.LINE_TYPE.INFO + '">' +
' <div class="d2h-code-side-line ' + diffParser.LINE_TYPE.INFO + '">' +
'File without changes' +
' </div>' +
' </td>\n' +
'</tr>\n';

@@ -198,10 +212,4 @@ return fileHtml;

// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["SideBySidePrinter"] = new SideBySidePrinter();
module.exports['SideBySidePrinter'] = new SideBySidePrinter();
})(this);

@@ -8,3 +8,3 @@ /*

(function (ctx, undefined) {
(function(ctx, undefined) {

@@ -14,26 +14,31 @@ function Utils() {

Utils.prototype.escape = function (str) {
Utils.prototype.escape = function(str) {
return str.slice(0)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\t/g, " ");
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\t/g, ' ');
};
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;
};
Utils.prototype.valueOrEmpty = function (value) {
return value ? value : "";
Utils.prototype.valueOrEmpty = function(value) {
return value ? value : '';
};
// expose this module
((typeof module !== 'undefined' && module.exports) ||
(typeof exports !== 'undefined' && exports) ||
(typeof window !== 'undefined' && window) ||
(typeof self !== 'undefined' && self) ||
(typeof $this !== 'undefined' && $this) ||
Function('return this')())["Utils"] = new Utils();
module.exports['Utils'] = new Utils();
})(this);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc