Author: | rtfpessoa |
---|---|
Views Total: | 1,884 views |
Official Page: | Go to website |
Last Update: | January 7, 2023 |
License: | MIT |
Preview:

Description:
diff2html.js is a tiny JavaScript library used to create a Github-style HTML diff tool with syntax highlighting for git diff output.
Installation:
# Yarn $ yarn add diff2html # NPM $ npm install diff2html --save
How to use it:
Include the diff2html.js and other required resources on the web page.
<!-- diff2html files --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/diff2html/dist/diff2html.min.css"> <script src="https://cdn.jsdelivr.net/npm/diff2html/dist/diff2html.min.js"></script>
Basic usage.
document.addEventListener('DOMContentLoaded', () => { var diffHtml = global.Diff2Html.html('<Unified Diff String>', { // options here }); document.getElementById('destination-elem-id').innerHTML = diffHtml; });
Available configurations with default values.
{ // the format of the input data: 'diff' or 'json', default is 'diff' inputFormat: 'diff', // show a file list before the diff drawFileList: '', // the format of the output data: 'line-by-line' or 'side-by-side' outputFormat: 'line-by-line', // show a file list before the diff: true or false, showFiles: false, // 'lines' for matching lines, 'words' for matching lines and words matching: 'none', // similarity threshold for word matching, default is matchWordsThreshold: .25 // perform at most this much comparisons for line matching a block of changes matchingMaxComparisons: 2500, // maximum number os characters of the bigger line in a block to apply comparison maxLineSizeInBlockForComparison: 200 // only perform diff changes highlight if lines are smaller than this maxLineLengthHighlight: 10000, // object with previously compiled templates to replace parts of the html templates: {} // object with raw not compiled templates to replace parts of the html rawTemplates: {}, // render nothing if the diff shows no change in its comparison renderNothingWhenEmpty: false }
Changelog:
v3.4.24 (01/07/2023)
- update
v3.4.22 (11/01/2022)
- bugfix
v3.4.20 (10/24/2022)
- update dependencies
v3.4.10 (09/02/2022)
- fix: Remove display block to allow hidding file contents
v3.4.8 (07/24/2022)
- Update dependencies
v3.4.3 (04/09/2022)
- Fix installation
v3.4.2 (04/05/2022)
- Update
v3.3.0 (03/05/2022)
- Bypass parsing/rendering of file diff if specific threshold is crossed
v3.2.0 (03/05/2022)
- Allow collapsing viewed files
v3.1.7 (05/09/2020)
- Update
v3.1.6 (03/15/2020)
- Update
v3.0.0beta (02/06/2020)
- Update
v2.12.2 (12/29/2019)
- Fix side-by-side line spacing
v2.12.2 (12/29/2019)
- Fix side-by-side line spacing
v2.12.1 (06/21/2019)
- Updated
v2.10.0 (06/21/2019)
- Add configuration option maxLineSizeInBlockForComparison to configure max line size to do comparisons per block. This options helps avoiding OOM in blocks with large line (e.g.: minified files).
v2.8.0 (05/02/2019)
- Fix linenumber scroll