Git-diff to html

I am looking for a way to create HTML files from git-diff output, preferably using python. I watched http://docs.python.org/library/difflib.html without being able to figure out how to use the output of git-diff as an input file.

Any clue?

Many thanks

+5
source share
3 answers

You can use the pygments commandline script to get the high level HTML output syntax.

Installation:

$ easy_install Pygments

Example:

$ git diff HEAD^1 > last.diff
$ pygmentize -f html -O full,style=trac -l diff -o last.diff.html last.diff

$ # mac only
$ open last.diff.html

Or shorter:

$ git diff | pygmentize -f html -O full,style=emacs -l diff

PS To view all available styles, try:

$ pygmentize -L styles

PPS To complete the pipeline, you can use this trick :

$ git diff | pygmentize -f html -O full,style=emacs -l diff | browser
+8

, difr - , . git style diff HTML-, , GitHub . ( . , , , .)

https://github.com/wspringer/difr

+1

I wrote a simple implementation for maildiff

def getHtml(diffData):
    """ This method convertes git diff data to html color code
    """
    openTag = "<span style='font-size: .80em; color: "
    openTagEnd = ";font-family: courier, arial, helvetica, sans-serif;'>"
    nbsp = '&nbsp;&nbsp;&nbsp;&nbsp;'
    return ''.join([("%s%s%s%s%s</span><br>" % (openTag, '#ff0000' if line.startswith('-') else ('#007900' if line.startswith('+') else '#000000'), openTagEnd, nbsp*line.count('\t') ,line)) for line in diffData]) 

take a look at it.

+1
source

All Articles