$ easy_install Pygments
例子:
$ 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
或者更简洁一些:
$ git diff | pygmentize -f html -O full,style=emacs -l diff
提示:要查看所有可用样式,请尝试:
$ pygmentize -L styles
另外,为了使管道完整,您可以使用这个技巧:
$ git diff | pygmentize -f html -O full,style=emacs -l diff | browser
我为我的 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 = ' '
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])
请看它。