Git-diff to HTML

前端 未结 3 1570
耶瑟儿~
耶瑟儿~ 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:33

    I wrote a simple implementation for my maildiff

    def getHtml(diffData):
        """ This method convertes git diff data to html color code
        """
        openTag = ""
        nbsp = '    '
        return ''.join([("%s%s%s%s%s
    " % (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.

提交回复
热议问题