diff2html/src/diff2html.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-04-12 01:59:54 +00:00
/*
*
* Diff to HTML (diff2html.js)
* Author: rtfpessoa
*
* Diff commands:
* git diff
*/
(function (global, undefined) {
var diffParser = require("./diff-parser.js").DiffParser;
var htmlPrinter = require("./html-printer.js").HtmlPrinter;
function Diff2Html() {
}
/*
* config
* {
* "wordByWord" : true (default)
* OR
* "charByChar" : true
* }
*
*/
2015-04-12 01:59:54 +00:00
/*
* Generates pretty html from string diff input
*/
Diff2Html.prototype.getPrettyHtmlFromDiff = function (diffInput, config) {
2015-04-12 01:59:54 +00:00
var diffJson = diffParser.generateDiffJson(diffInput);
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
*/
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
*/
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput, config) {
2015-04-12 01:59:54 +00:00
var diffJson = diffParser.generateDiffJson(diffInput);
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
*/
Diff2Html.prototype.getPrettySideBySideHtmlFromJson = function (diffJson, config) {
var configOrEmpty = config || {};
return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty);
2015-04-12 01:59:54 +00:00
};
if (typeof module !== 'undefined' && module.exports) {
module.exports.Diff2Html = new Diff2Html();
} else if (typeof global.Diff2Html === 'undefined') {
global.Diff2Html = new Diff2Html();
}
})(this);