2015-04-12 01:59:54 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Diff to HTML (diff2html.js)
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
(function() {
|
2015-08-08 00:11:35 +00:00
|
|
|
var diffParser = require('./diff-parser.js').DiffParser;
|
|
|
|
|
var htmlPrinter = require('./html-printer.js').HtmlPrinter;
|
2015-04-12 01:59:54 +00:00
|
|
|
|
|
|
|
|
function Diff2Html() {
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 10:32:37 +00:00
|
|
|
/*
|
2015-07-19 21:08:17 +00:00
|
|
|
* Line diff type configuration
|
|
|
|
|
var config = {
|
2015-12-20 22:22:58 +00:00
|
|
|
'wordByWord': true, // (default)
|
2015-07-19 21:08:17 +00:00
|
|
|
// OR
|
2015-12-20 22:22:58 +00:00
|
|
|
'charByChar': true
|
2015-07-19 21:08:17 +00:00
|
|
|
};
|
2015-04-12 10:32:37 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-04-12 01:59:54 +00:00
|
|
|
/*
|
2015-10-19 11:47:49 +00:00
|
|
|
* Generates json object from string diff input
|
2015-04-12 01:59:54 +00:00
|
|
|
*/
|
2016-02-23 18:21:34 +00:00
|
|
|
Diff2Html.prototype.getJsonFromDiff = function(diffInput, config) {
|
|
|
|
|
var configOrEmpty = config || {};
|
|
|
|
|
return diffParser.generateDiffJson(diffInput, configOrEmpty);
|
2015-10-19 11:47:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates the html diff. The config parameter configures the output/input formats and other options
|
|
|
|
|
*/
|
|
|
|
|
Diff2Html.prototype.getPrettyHtml = function(diffInput, config) {
|
2015-04-12 10:32:37 +00:00
|
|
|
var configOrEmpty = config || {};
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
var diffJson = diffInput;
|
2015-12-20 22:22:58 +00:00
|
|
|
if (!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') {
|
2016-02-23 18:21:34 +00:00
|
|
|
diffJson = diffParser.generateDiffJson(diffInput, configOrEmpty);
|
2015-10-19 11:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
var fileList = '';
|
|
|
|
|
if (configOrEmpty.showFiles === true) {
|
2016-10-09 15:41:54 +00:00
|
|
|
fileList = htmlPrinter.generateFileListSummary(diffJson, configOrEmpty);
|
2015-10-19 11:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
var diffOutput = '';
|
|
|
|
|
if (configOrEmpty.outputFormat === 'side-by-side') {
|
2015-10-19 11:47:49 +00:00
|
|
|
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
|
|
|
|
} else {
|
|
|
|
|
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
return fileList + diffOutput;
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
2015-10-19 11:47:49 +00:00
|
|
|
* Deprecated methods - The following methods exist only to maintain compatibility with previous versions
|
2015-04-12 01:59:54 +00:00
|
|
|
*/
|
2015-10-19 11:47:49 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty html from string diff input
|
|
|
|
|
*/
|
|
|
|
|
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) {
|
|
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
configOrEmpty.inputFormat = 'diff';
|
|
|
|
|
configOrEmpty.outputFormat = 'line-by-line';
|
|
|
|
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty html from a json object
|
|
|
|
|
*/
|
2015-08-08 00:11:35 +00:00
|
|
|
Diff2Html.prototype.getPrettyHtmlFromJson = function(diffJson, config) {
|
2015-04-12 10:32:37 +00:00
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
configOrEmpty.inputFormat = 'json';
|
|
|
|
|
configOrEmpty.outputFormat = 'line-by-line';
|
|
|
|
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty side by side html from string diff input
|
|
|
|
|
*/
|
2015-08-08 00:11:35 +00:00
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) {
|
2015-04-12 10:32:37 +00:00
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
configOrEmpty.inputFormat = 'diff';
|
|
|
|
|
configOrEmpty.outputFormat = 'side-by-side';
|
|
|
|
|
return this.getPrettyHtml(diffInput, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty side by side html from a json object
|
|
|
|
|
*/
|
2015-08-08 00:11:35 +00:00
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function(diffJson, config) {
|
2015-04-12 10:32:37 +00:00
|
|
|
var configOrEmpty = config || {};
|
2015-12-20 22:22:58 +00:00
|
|
|
configOrEmpty.inputFormat = 'json';
|
|
|
|
|
configOrEmpty.outputFormat = 'side-by-side';
|
|
|
|
|
return this.getPrettyHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
var diffObject = new Diff2Html();
|
2015-12-20 22:22:58 +00:00
|
|
|
module.exports.Diff2Html = diffObject;
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
// Expose diff2html in the browser
|
2015-12-20 22:22:58 +00:00
|
|
|
global.Diff2Html = diffObject;
|
|
|
|
|
})();
|