2015-04-12 01:59:54 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Diff to HTML (diff2html.js)
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-19 21:08:17 +00:00
|
|
|
(function (ctx, undefined) {
|
2015-04-12 01:59:54 +00:00
|
|
|
|
|
|
|
|
var diffParser = require("./diff-parser.js").DiffParser;
|
|
|
|
|
var htmlPrinter = require("./html-printer.js").HtmlPrinter;
|
|
|
|
|
|
|
|
|
|
function Diff2Html() {
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-12 10:32:37 +00:00
|
|
|
/*
|
2015-07-19 21:08:17 +00:00
|
|
|
* Line diff type configuration
|
|
|
|
|
var config = {
|
|
|
|
|
"wordByWord": true, // (default)
|
|
|
|
|
// OR
|
|
|
|
|
"charByChar": true
|
|
|
|
|
};
|
2015-04-12 10:32:37 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-04-12 01:59:54 +00:00
|
|
|
/*
|
|
|
|
|
* Generates pretty html from string diff input
|
|
|
|
|
*/
|
2015-04-12 10:32:37 +00:00
|
|
|
Diff2Html.prototype.getPrettyHtmlFromDiff = function (diffInput, config) {
|
2015-04-12 01:59:54 +00:00
|
|
|
var diffJson = diffParser.generateDiffJson(diffInput);
|
2015-04-12 10:32:37 +00:00
|
|
|
var configOrEmpty = config || {};
|
|
|
|
|
return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates json object from string diff input
|
|
|
|
|
*/
|
|
|
|
|
Diff2Html.prototype.getJsonFromDiff = function (diffInput) {
|
|
|
|
|
return diffParser.generateDiffJson(diffInput);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty html from a json object
|
|
|
|
|
*/
|
2015-04-12 10:32:37 +00:00
|
|
|
Diff2Html.prototype.getPrettyHtmlFromJson = function (diffJson, config) {
|
|
|
|
|
var configOrEmpty = config || {};
|
|
|
|
|
return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty side by side html from string diff input
|
|
|
|
|
*/
|
2015-04-12 10:32:37 +00:00
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput, config) {
|
2015-04-12 01:59:54 +00:00
|
|
|
var diffJson = diffParser.generateDiffJson(diffInput);
|
2015-04-12 10:32:37 +00:00
|
|
|
|
|
|
|
|
var configOrEmpty = config || {};
|
|
|
|
|
return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generates pretty side by side html from a json object
|
|
|
|
|
*/
|
2015-04-12 10:32:37 +00:00
|
|
|
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function (diffJson, config) {
|
|
|
|
|
var configOrEmpty = config || {};
|
|
|
|
|
return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
2015-07-19 21:08:17 +00:00
|
|
|
// 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();
|
2015-04-12 01:59:54 +00:00
|
|
|
|
|
|
|
|
})(this);
|