5.2.15 • Published 3 months ago

diff2html-cli v5.2.15

Weekly downloads
4,138
License
MIT
Repository
github
Last release
3 months ago

diff2html-cli

npm node npm GitHub Actions

npm weekly downloads npm monthly downloads npm yearly downloads npm downloads

Diff to Html generates pretty HTML diffs from unified and git diff output in your terminal

Table of Contents

Features

  • Unified diff and Git diff input

  • line-by-line and side-by-side diff

  • new and old line numbers

  • inserted and removed lines

  • GitHub like style

  • Code syntax highlight

  • Line similarity matching

Online Example

Go to Diff2HTML

Distributions

Setup

npm install -g diff2html-cli

Usage

Usage: diff2html flags and/or options -- git diff passthrough flags and options

flagaliasdescriptionchoicesdefault
-s--styleOutput styleline, sideline
--fct--fileContentToggleAdds a viewed checkbox to toggle file contenttrue, falsetrue
--sc--synchronisedScrollSynchronised horizontal scrolltrue, falsetrue
--hc--highlightCodeHighlight codetrue, falsetrue
--cs--colorSchemeColor schemeauto, dark, lightauto
--su--summaryShow files summaryclosed, open, hiddenclosed
-d--diffStyleDiff styleword, charword
--lm--matchingDiff line matching typelines, words, nonenone
--lmt--matchWordsThresholdDiff line matching word threshold0.25
--lmm--matchingMaxComparisonsDiff line matching maximum line comparisons of a block of changes2500
--diffMaxChangesNumber of changed lines after which a file diff is deemed as too big and not displayed
--diffMaxLineLengthNumber of characters in a diff line after which a file diff is deemed as too big and not displayed
--renderNothingWhenEmptyRender nothing if the diff shows no change in its comparisonfalse
--maxLineSizeInBlockForComparisonMaximum number of characters of the bigger line in a block to apply comparison200
--maxLineLengthHighlightMaximum number of characters in a line to apply highlight10000
--hwt--htmlWrapperTemplatePath to custom template to be rendered when using the html output format[string]
-t--titlePage title for html output[string]
-f--formatOutput formathtml, jsonhtml
-i--inputDiff input sourcefile, command, stdincommand
-o--outputOutput destinationpreview, stdoutpreview
-u--diffyUpload to diffy.orgbrowser, pbcopy, print
-F--fileSend output to file (overrides output option)[string]
--ig--ignoreIgnore particular files from the diff[string]
-v--versionShow version number
-h--helpShow help

Exit Status Codes

  • :tada: 0: Success
  • :dizzy_face: 1: Generic Error
  • :cold_sweat: 3: Input diff is empty
  • :cop: 4: Value of --hwt | --htmlWrapperTemplate is not a valid file

Custom HTML wrapper template

The template is a very based on a simple replace of several placeholders as coded https://github.com/rtfpessoa/diff2html-cli/blob/master/src/cli.ts#L40

To provide a custom template you need to make sure you have the following comments and imports in your HTML, exactly as they are here:

  • Inside the <head> tag
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css" />
<!--diff2html-css-->
<!--diff2html-js-ui-->
<script>
  document.addEventListener('DOMContentLoaded', () => {
    const targetElement = document.getElementById('diff');
    const diff2htmlUi = new Diff2HtmlUI(targetElement);
    //diff2html-fileListToggle
    //diff2html-synchronisedScroll
    //diff2html-highlightCode
  });
</script>
  • Inside the <body> tag
<div id="diff">
  <!--diff2html-diff-->
</div>

Examples

diff2html -s line -f html -d word -i command -o preview -- -M HEAD~1

  • diff last commit, line by line, word comparison between lines, previewed in the browser and input from git diff command

diff2html -i file -- my-file-diff.diff

  • reading the input from a file

diff -u file1.txt file2.txt | diff2html -i stdin

  • reading diff from stdin

diff2html -f json -o stdout -- -M HEAD~1

  • print json format to stdout

diff2html -F my-pretty-diff.html -- -M HEAD~1

  • print to file

diff2html -F my-pretty-diff.html --hwt my-custom-template.html -- -M HEAD~1

  • print to file using custom markup templates can include the following variables

diff2html --ig package-lock.json --ig yarn.lock

  • Ignore package-lock.json and yarn.lock from the generated diff

NOTE: notice the -- in the examples

Contribute

This is a developer friendly project, all the contributions are welcome. To contribute just send a pull request with your changes following the guidelines described in CONTRIBUTING.md. I will try to review them as soon as possible.

Developing

Make some changes, yarn build and then ./bin/diff2html 😉

License

Copyright 2014-present Rodrigo Fernandes. Released under the terms of the MIT license.

Thanks

This project is inspired in pretty-diff by Scott González.


5.2.15

3 months ago

5.2.14

3 months ago

5.2.13

9 months ago

5.2.12

9 months ago

5.2.11

9 months ago

5.2.10

9 months ago

5.2.9

1 year ago

5.2.8

1 year ago

5.2.7

1 year ago

5.2.6

2 years ago

5.2.5

2 years ago

5.2.4

2 years ago

5.2.3

2 years ago

5.2.2

2 years ago

5.2.1

2 years ago

5.2.0

2 years ago

5.1.11

3 years ago

5.1.10

3 years ago

5.1.9

3 years ago

5.1.8

3 years ago

5.1.7

3 years ago

5.1.6

4 years ago

5.1.5

4 years ago

5.1.4

4 years ago

5.1.3

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.7.0

5 years ago

2.6.0

6 years ago

2.5.4

6 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.4.6-rc.3

8 years ago

1.4.6-rc.2

8 years ago

1.4.6-rc.1

8 years ago

1.4.6-beta6

8 years ago

1.4.6-beta5

8 years ago

1.4.6-beta4

8 years ago

1.4.6-beta3

8 years ago

1.4.6-beta2

8 years ago

1.4.6-beta1

8 years ago

1.4.5

8 years ago

1.4.4

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.4.0-windows1

8 years ago

1.3.0

8 years ago

1.2.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

1.0.0-2

9 years ago

1.0.0-1

9 years ago

0.2.4-1

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.2.0-3

9 years ago

0.2.0-2

9 years ago

0.2.0-1

9 years ago

0.1.0

9 years ago