Skip to content

Instantly share code, notes, and snippets.

@sanfx
Last active February 7, 2018 23:59
Show Gist options
  • Save sanfx/8620493 to your computer and use it in GitHub Desktop.
Save sanfx/8620493 to your computer and use it in GitHub Desktop.
convert git diff to color HTML for embed to webpage or email using python
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment