Git-diff to HTML

前端 未结 3 1548
耶瑟儿~
耶瑟儿~ 2021-02-09 23:06

I\'m looking for a way to produce HTML files from a git-diff output, preferably using python. I\'ve been looking at http://docs.python.org/library/difflib.html without being abl

相关标签:
3条回答
  • 2021-02-09 23:21

    Perhaps difr is you what you're looking for. It takes any kind git style diff as an input and produces an HTML version of it that is pretty to similar to what GitHub would give you. (And it embeds an editor for adding some small comments. That might be a little more than what you asked for, but I don't think it gets in the way.)

    https://github.com/wspringer/difr

    0 讨论(0)
  • 2021-02-09 23:28

    You could use the pygments commandline script to get a syntax highligthed HTML output.

    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
    

    P.S. To see all available styles, try:

    $ pygmentize -L styles
    

    P.P.S. To make the pipeline complete, you can use this trick:

    $ git diff | pygmentize -f html -O full,style=emacs -l diff | browser
    
    0 讨论(0)
  • 2021-02-09 23:33

    I wrote a simple implementation for my 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]) 
    

    have a look at it.

    0 讨论(0)
提交回复
热议问题