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

diff2html

Package Overview
Dependencies
Maintainers
1
Versions
210
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 1.3.2 to 2.0.0-beta1

dist/diff2html-templates.js

19

dist/diff2html-ui.js

@@ -117,4 +117,2 @@ /******/ (function(modules) { // webpackBootstrap

console.log(languages);
// pass the languages to the highlightjs plugin

@@ -150,3 +148,2 @@ hljs.configure({languages: languages});

} else {
console.log($target.find(".d2h-file-wrapper"));
$target.find(".d2h-file-wrapper").map(function(i, file) {

@@ -157,8 +154,4 @@ allFileLanguages.push($(file).data("lang"));

// remove duplicated languages
var distinctLanguages = allFileLanguages.filter(function(v, i) {
return allFileLanguages.indexOf(v) === i;
});
return distinctLanguages;
// return only distinct languages
return this._distinct(allFileLanguages);
};

@@ -171,3 +164,3 @@

var hashTag = null;
if (hashTagIndex != -1) {
if (hashTagIndex !== -1) {
hashTag = docUrl.substr(hashTagIndex + 1);

@@ -179,2 +172,8 @@ }

Diff2HtmlUI.prototype._distinct = function(collection) {
return collection.filter(function(v, i) {
return collection.indexOf(v) === i;
});
};
module.exports.Diff2HtmlUI = Diff2HtmlUI;

@@ -181,0 +180,0 @@

@@ -1,1 +0,1 @@

!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),hashTag=this._getHashTag(),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");"files-summary-show"===hashTag?show():"files-summary-hide"===hashTag?hide():startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);console.log(languages),hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return $target=$(targetId?targetId:defaultTarget)},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):(console.log($target.find(".d2h-file-wrapper")),$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}));var distinctLanguages=allFileLanguages.filter(function(v,i){return allFileLanguages.indexOf(v)===i});return distinctLanguages},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!=hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]);
!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){(function(global){!function(){function Diff2HtmlUI(config){var cfg=config||{};cfg.diff?diffJson=Diff2Html.getJsonFromDiff(cfg.diff):cfg.json&&(diffJson=cfg.json)}var diffJson=null,defaultTarget="body";Diff2HtmlUI.prototype.draw=function(targetId,config){var cfg=config||{},$target=this._getTarget(targetId);$target.html(Diff2Html.getPrettyHtml(diffJson,cfg))},Diff2HtmlUI.prototype.fileListCloseable=function(targetId,startVisible){function show(){$showBtn.hide(),$hideBtn.show(),$fileList.show()}function hide(){$hideBtn.hide(),$showBtn.show(),$fileList.hide()}var $target=this._getTarget(targetId),hashTag=this._getHashTag(),$showBtn=$target.find(".d2h-show"),$hideBtn=$target.find(".d2h-hide"),$fileList=$target.find(".d2h-file-list");"files-summary-show"===hashTag?show():"files-summary-hide"===hashTag?hide():startVisible?show():hide(),$showBtn.click(show),$hideBtn.click(hide)},Diff2HtmlUI.prototype.highlightCode=function(targetId){var that=this,$target=that._getTarget(targetId),languages=that._getLanguages($target);hljs.configure({languages:languages});var $codeLines=$target.find(".d2h-code-line-ctn");$codeLines.map(function(i,line){hljs.highlightBlock(line)})},Diff2HtmlUI.prototype._getTarget=function(targetId){var $target;return $target=$(targetId?targetId:defaultTarget)},Diff2HtmlUI.prototype._getLanguages=function($target){var allFileLanguages=[];return diffJson?allFileLanguages=diffJson.map(function(line){return line.language}):$target.find(".d2h-file-wrapper").map(function(i,file){allFileLanguages.push($(file).data("lang"))}),this._distinct(allFileLanguages)},Diff2HtmlUI.prototype._getHashTag=function(){var docUrl=document.URL,hashTagIndex=docUrl.indexOf("#"),hashTag=null;return-1!==hashTagIndex&&(hashTag=docUrl.substr(hashTagIndex+1)),hashTag},Diff2HtmlUI.prototype._distinct=function(collection){return collection.filter(function(v,i){return collection.indexOf(v)===i})},module.exports.Diff2HtmlUI=Diff2HtmlUI,global.Diff2HtmlUI=Diff2HtmlUI}()}).call(exports,function(){return this}())}]);
{
"name": "diff2html",
"version": "1.3.2",
"version": "2.0.0-beta1",
"homepage": "http://rtfpessoa.github.io/diff2html/",

@@ -46,10 +46,11 @@ "description": "Fast Diff to colorized HTML",

"dependencies": {
"diff": "^2.2.1"
"diff": "^2.2.1",
"nunjucks": "^2.3.0"
},
"devDependencies": {
"clean-css": "^3.4.9",
"codacy-coverage": "^1.1.3",
"clean-css": "^3.4.9",
"fast-html-parser": "^1.0.1",
"istanbul": "^0.4.1",
"jscs": "^2.9.0",
"istanbul": "^0.4.2",
"jscs": "^2.10.1",
"mocha": "^2.4.5",

@@ -56,0 +57,0 @@ "uglifyjs": "^2.4.10",

@@ -8,4 +8,4 @@ # diff2html

[![npm](https://img.shields.io/npm/v/diff2html.svg)](https://www.npmjs.com/package/diff2html)
[![David](https://img.shields.io/david/rtfpessoa/diff2html.svg)](https://david-dm.org/rtfpessoa/diff2html)
[![David](https://img.shields.io/david/dev/rtfpessoa/diff2html.svg)](https://david-dm.org/rtfpessoa/diff2html)
[![Dependency Status](https://david-dm.org/rtfpessoa/diff2html.svg)](https://david-dm.org/rtfpessoa/diff2html)
[![devDependency Status](https://david-dm.org/rtfpessoa/diff2html/dev-status.svg)](https://david-dm.org/rtfpessoa/diff2html#info=devDependencies)

@@ -12,0 +12,0 @@ [![node](https://img.shields.io/node/v/diff2html.svg)]()

@@ -17,9 +17,9 @@ /*

return '<div class="d2h-file-list-wrapper">\n' +
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' +
' <a class="d2h-file-switch d2h-hide">hide</a>\n' +
' <a class="d2h-file-switch d2h-show">show</a>\n' +
' <div class="d2h-clear"></div>\n' +
' <div class="d2h-file-list-header">\n' +
' <span class="d2h-file-list-title">Files changed (' + diffFiles.length + ')&nbsp&nbsp</span>\n' +
' <a class="d2h-file-switch d2h-hide">hide</a>\n' +
' <a class="d2h-file-switch d2h-show">show</a>\n' +
' </div>\n' +
' <table class="d2h-file-list">\n' +
diffFiles.map(function(file) {

@@ -33,4 +33,7 @@ return ' <tr class="d2h-file-list-line">\n' +

' </td>\n' +
' <td class="d2h-file-name"><a href="#' + printerUtils.getHtmlId(file) + '">' +
'&nbsp;' + printerUtils.getDiffName(file) + '</a></td>\n' +
' <td class="d2h-file-name-wrapper">\n' +
' <a href="#' + printerUtils.getHtmlId(file) + '" class="d2h-file-name">' +
'&nbsp;' + printerUtils.getDiffName(file) +
' </a>\n' +
' </td>\n' +
' </tr>\n';

@@ -37,0 +40,0 @@ }).join('\n') +

@@ -15,2 +15,5 @@ /*

var nunjucksUtils = require('./nunjucks-utils.js').NunjucksUtils;
var baseTemplatesPath = 'line-by-line';
function LineByLinePrinter(config) {

@@ -21,39 +24,22 @@ this.config = config;

LineByLinePrinter.prototype.makeFileDiffHtml = function(file, diffs) {
return '<div id="' + printerUtils.getHtmlId(file) + '" 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">' +
' <span>+' + file.addedLines + '</span>\n' +
' </span>\n' +
' <span class="d2h-lines-deleted">' +
' <span>-' + file.deletedLines + '</span>\n' +
' </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';
return nunjucksUtils.render(baseTemplatesPath, 'file-diff.html', {'file': file, 'diffs': diffs});
};
LineByLinePrinter.prototype.makeLineByLineHtmlWrapper = function(content) {
return nunjucksUtils.render(baseTemplatesPath, 'wrapper.html', {'content': content});
};
LineByLinePrinter.prototype.generateLineByLineJsonHtml = function(diffFiles) {
var that = this;
var htmlDiffs = diffFiles.map(function(file) {
var diffs;
if (file.blocks.length) {
diffs = that._generateFileHtml(file);
} else {
diffs = that._generateEmptyDiff();
}
return that.makeFileDiffHtml(file, diffs);
});
var diffs;
if (file.blocks.length) {
diffs = that._generateFileHtml(file);
} else {
diffs = that._generateEmptyDiff();
}
return that.makeFileDiffHtml(file, diffs);
});
return '<div class="d2h-wrapper">\n' + htmlDiffs.join('\n') + '</div>\n';
return this.makeLineByLineHtmlWrapper(htmlDiffs.join('\n'));
};

@@ -69,8 +55,3 @@

LineByLinePrinter.prototype.makeColumnLineNumberHtml = function(block) {
return '<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';
return nunjucksUtils.render(baseTemplatesPath, 'column-line-number.html', {block: block});
};

@@ -121,6 +102,6 @@

processedOldLines +=
that._generateLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
that.makeLineHtml(deleteType, oldLine.oldNumber, oldLine.newNumber,
diff.first.line, diff.first.prefix);
processedNewLines +=
that._generateLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
that.makeLineHtml(insertType, newLine.oldNumber, newLine.newNumber,
diff.second.line, diff.second.prefix);

@@ -147,5 +128,5 @@ }

if (line.type === diffParser.LINE_TYPE.CONTEXT) {
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
lines += that._generateLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
lines += that.makeLineHtml(line.type, line.oldNumber, line.newNumber, escapedLine);
} else if (line.type === diffParser.LINE_TYPE.DELETES) {

@@ -173,3 +154,3 @@ oldLines.push(line);

var oldEscapedLine = utils.escape(oldLine.content);
lines += this._generateLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
lines += this.makeLineHtml(oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine);
}

@@ -180,3 +161,3 @@

var newEscapedLine = utils.escape(newLine.content);
lines += this._generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
lines += this.makeLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine);
}

@@ -187,36 +168,15 @@

LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, htmlPrefix, htmlContent) {
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';
LineByLinePrinter.prototype.makeLineHtml = function(type, oldNumber, newNumber, content, prefix) {
return nunjucksUtils.render(baseTemplatesPath, 'line.html',
{
type: type,
oldNumber: oldNumber,
newNumber: newNumber,
prefix: prefix,
content: content
});
};
LineByLinePrinter.prototype._generateLineHtml = function(type, oldNumber, newNumber, content, prefix) {
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>';
}
return this.makeLineHtml(type, oldNumber, newNumber, htmlPrefix, htmlContent);
};
LineByLinePrinter.prototype._generateEmptyDiff = function() {
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 nunjucksUtils.render(baseTemplatesPath, 'empty-diff.html', {});
};

@@ -223,0 +183,0 @@

@@ -29,11 +29,13 @@ /*

' <div class="d2h-file-header">\n' +
' <div class="d2h-file-stats">\n' +
' <span class="d2h-lines-added">' +
' <span class="d2h-file-stats">\n' +
' <span class="d2h-lines-added">\n' +
' <span>+' + file.addedLines + '</span>\n' +
' </span>\n' +
' <span class="d2h-lines-deleted">' +
' <span class="d2h-lines-deleted">\n' +
' <span>-' + file.deletedLines + '</span>\n' +
' </span>\n' +
' </div>\n' +
' <div class="d2h-file-name">' + printerUtils.getDiffName(file) + '</div>\n' +
' </span>\n' +
' <span class="d2h-file-name-wrapper">\n' +
' <span class="d2h-file-name">' + printerUtils.getDiffName(file) + '</span>\n' +
' </span>\n' +
' </div>\n' +

@@ -40,0 +42,0 @@ ' <div class="d2h-files-diff">\n' +

@@ -71,4 +71,2 @@ /*

console.log(languages);
// pass the languages to the highlightjs plugin

@@ -104,3 +102,2 @@ hljs.configure({languages: languages});

} else {
console.log($target.find(".d2h-file-wrapper"));
$target.find(".d2h-file-wrapper").map(function(i, file) {

@@ -111,8 +108,4 @@ allFileLanguages.push($(file).data("lang"));

// remove duplicated languages
var distinctLanguages = allFileLanguages.filter(function(v, i) {
return allFileLanguages.indexOf(v) === i;
});
return distinctLanguages;
// return only distinct languages
return this._distinct(allFileLanguages);
};

@@ -125,3 +118,3 @@

var hashTag = null;
if (hashTagIndex != -1) {
if (hashTagIndex !== -1) {
hashTag = docUrl.substr(hashTagIndex + 1);

@@ -133,2 +126,8 @@ }

Diff2HtmlUI.prototype._distinct = function(collection) {
return collection.filter(function(v, i) {
return collection.indexOf(v) === i;
});
};
module.exports.Diff2HtmlUI = Diff2HtmlUI;

@@ -135,0 +134,0 @@

@@ -13,2 +13,6 @@ /*

Utils.prototype.convertWhiteSpaceToNonBreakingSpace = function(str) {
return str.slice(0).replace(/ /g, '&nbsp;');
};
Utils.prototype.escape = function(str) {

@@ -15,0 +19,0 @@ return str.slice(0)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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