@recipyGui.template_filter()
def colordiff(diff):
    if diff == '':
        return ''
    diff = diff.strip()
    diff = diff.replace('\n', '&nbsp;\n')
    diffData = diff.split('\n')
    openTag = '<tr><td class="'
    openTagEnd = '">'
    nbsp = '&nbsp;&nbsp;&nbsp;&nbsp;'
    data = '\n'.join([('%s%s%s%s<samp>%s</samp><td></tr>' %
                      (openTag,
                       'bg-danger' if line.startswith('-')
                       else ('bg-success' if line.startswith('+')
                             else ('bg-info' if line.startswith('@')
                                   else '')),
                       openTagEnd,
                       nbsp * line.count('\t'), line)) for line in diffData])
    return '<table width="100%">' + data + '</table>'
convert git diff data to html/bootstrap color code
dataset/ETHPy150Open recipy/recipy/recipyGui/__init__.py/colordiff