diff2html
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "diff2html", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"homepage": "http://rtfpessoa.github.io/diff2html/", | ||
@@ -5,0 +5,0 @@ "description": "Fast Diff to colorized HTML", |
@@ -35,10 +35,6 @@ # Diff to Html by [rtfpessoa](https://github.com/rtfpessoa) | ||
> Pretty Line-by-Line Html From Git Word Diff Output | ||
> Pretty HTML diff | ||
Diff2Html.getPrettyHtmlFromDiff(exInput) | ||
Diff2Html.getPrettyHtml(exInput, configuration) | ||
> Pretty Side-by-Side Html From Git Word Diff Output | ||
Diff2Html.getPrettySideBySideHtmlFromDiff(exInput) | ||
> Intermediate Json From Git Word Diff Output | ||
@@ -48,14 +44,14 @@ | ||
> Pretty Line-by-Line Html From Json | ||
> Check out the `index.html` for a complete example. | ||
Diff2Html.getPrettyHtmlFromJson(exInput) | ||
## Configuration | ||
The HTML output accepts a Javascript object with configuration. Possible options: | ||
> Pretty Side-by-Side Html From Json | ||
- `inputFormat`: the format of the input data: `'diff'` or `'json'`, default is `'diff'` | ||
- `outputFormat`: the format of the output data: `'line-by-line'` or `'side-by-side'`, default is `'line-by-line'` | ||
- `showFiles`: show a file list before the diff: `true` or `false`, default is `false` | ||
Diff2Html.getPrettySideBySideHtmlFromJson(exInput) | ||
> Check out the `index.html` for a complete example. | ||
## Syntax Highlight | ||
## Sintax Hightlight | ||
> Add the dependencies. | ||
@@ -95,4 +91,4 @@ Choose one color scheme, and add the main highlight code. | ||
// generate and inject the diff HTML into the desired place | ||
document.getElementById("line-by-line").innerHTML = Diff2Html.getPrettyHtmlFromJson(diffJson); | ||
document.getElementById("side-by-side").innerHTML = Diff2Html.getPrettySideBySideHtmlFromJson(diffJson); | ||
document.getElementById("line-by-line").innerHTML = Diff2Html.getPrettyHtml(diffJson, { inputFormat: 'json' }); | ||
document.getElementById("side-by-side").innerHTML = Diff2Html.getPrettyHtml(diffJson, { inputFormat: 'json', outputFormat: 'side-by-side' }); | ||
@@ -99,0 +95,0 @@ // collect all the code lines and execute the highlight on them |
@@ -11,2 +11,3 @@ /* | ||
var diffParser = require('./diff-parser.js').DiffParser; | ||
var fileLister = require('./file-list-printer.js').FileListPrinter; | ||
var htmlPrinter = require('./html-printer.js').HtmlPrinter; | ||
@@ -27,15 +28,47 @@ | ||
/* | ||
* Generates pretty html from string diff input | ||
* Generates json object from string diff input | ||
*/ | ||
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { | ||
var diffJson = diffParser.generateDiffJson(diffInput); | ||
Diff2Html.prototype.getJsonFromDiff = function(diffInput) { | ||
return diffParser.generateDiffJson(diffInput); | ||
}; | ||
/* | ||
* Generates the html diff. The config parameter configures the output/input formats and other options | ||
*/ | ||
Diff2Html.prototype.getPrettyHtml = function(diffInput, config) { | ||
var configOrEmpty = config || {}; | ||
return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); | ||
var diffJson = diffInput; | ||
if(!configOrEmpty.inputFormat || configOrEmpty.inputFormat === 'diff') { | ||
diffJson = diffParser.generateDiffJson(diffInput); | ||
} | ||
var fileList = ""; | ||
if(configOrEmpty.showFiles === true) { | ||
fileList = fileLister.generateFileList(diffJson, configOrEmpty); | ||
} | ||
var diffOutput = ""; | ||
if(configOrEmpty.outputFormat === 'side-by-side') { | ||
diffOutput = htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); | ||
} else { | ||
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); | ||
} | ||
return fileList + diffOutput | ||
}; | ||
/* | ||
* Generates json object from string diff input | ||
* Deprecated methods - The following methods exist only to maintain compatibility with previous versions | ||
*/ | ||
Diff2Html.prototype.getJsonFromDiff = function(diffInput) { | ||
return diffParser.generateDiffJson(diffInput); | ||
/* | ||
* Generates pretty html from string diff input | ||
*/ | ||
Diff2Html.prototype.getPrettyHtmlFromDiff = function(diffInput, config) { | ||
var configOrEmpty = config || {}; | ||
configOrEmpty['inputFormat'] = 'diff'; | ||
configOrEmpty['outputFormat'] = 'line-by-line'; | ||
return this.getPrettyHtml(diffInput, configOrEmpty) | ||
}; | ||
@@ -48,3 +81,5 @@ | ||
var configOrEmpty = config || {}; | ||
return htmlPrinter.generateLineByLineJsonHtml(diffJson, configOrEmpty); | ||
configOrEmpty['inputFormat'] = 'json'; | ||
configOrEmpty['outputFormat'] = 'line-by-line'; | ||
return this.getPrettyHtml(diffJson, configOrEmpty) | ||
}; | ||
@@ -56,6 +91,6 @@ | ||
Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function(diffInput, config) { | ||
var diffJson = diffParser.generateDiffJson(diffInput); | ||
var configOrEmpty = config || {}; | ||
return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); | ||
configOrEmpty['inputFormat'] = 'diff'; | ||
configOrEmpty['outputFormat'] = 'side-by-side'; | ||
return this.getPrettyHtml(diffInput, configOrEmpty) | ||
}; | ||
@@ -68,3 +103,5 @@ | ||
var configOrEmpty = config || {}; | ||
return htmlPrinter.generateSideBySideJsonHtml(diffJson, configOrEmpty); | ||
configOrEmpty['inputFormat'] = 'json'; | ||
configOrEmpty['outputFormat'] = 'side-by-side'; | ||
return this.getPrettyHtml(diffJson, configOrEmpty) | ||
}; | ||
@@ -71,0 +108,0 @@ |
@@ -28,3 +28,3 @@ /* | ||
return '<div class="d2h-file-wrapper" data-lang="' + file.language + '">\n' + | ||
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' + | ||
' <div class="d2h-file-header">\n' + | ||
@@ -31,0 +31,0 @@ ' <div class="d2h-file-stats">\n' + |
@@ -16,2 +16,17 @@ /* | ||
PrinterUtils.prototype.getHtmlId = function(file) { | ||
var hashCode = function(text) { | ||
var hash = 0, i, chr, len; | ||
if (text.length == 0) return hash; | ||
for (i = 0, len = text.length; i < len; i++) { | ||
chr = text.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; // Convert to 32bit integer | ||
} | ||
return hash; | ||
}; | ||
return "d2h-" + hashCode(this.getDiffName(file)).toString().slice(-6); | ||
}; | ||
PrinterUtils.prototype.getDiffName = function(file) { | ||
@@ -18,0 +33,0 @@ var oldFilename = file.oldName; |
@@ -28,3 +28,3 @@ /* | ||
return '<div class="d2h-file-wrapper" data-lang="' + file.language + '">\n' + | ||
return '<div id="' + printerUtils.getHtmlId(file) + '" class="d2h-file-wrapper" data-lang="' + file.language + '">\n' + | ||
' <div class="d2h-file-header">\n' + | ||
@@ -31,0 +31,0 @@ ' <div class="d2h-file-stats">\n' + |
@@ -21,2 +21,6 @@ /* | ||
Utils.prototype.getRandomId = function(prefix) { | ||
return prefix + "-" + Math.random().toString(36).slice(-3); | ||
}; | ||
Utils.prototype.startsWith = function(str, start) { | ||
@@ -23,0 +27,0 @@ if (typeof start === 'object') { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34687
11
762
115