Skip to content

Instantly share code, notes, and snippets.

@jaredks
Last active August 29, 2015 14:07
Show Gist options
  • Save jaredks/1a17bf34c520aefa7dda to your computer and use it in GitHub Desktop.
Save jaredks/1a17bf34c520aefa7dda to your computer and use it in GitHub Desktop.
Create html diff of two given lists
import difflib
import re
def html_diff(list1, list2, title='', left='', right=''):
"""Returns HTML as string representing a visual diff for the given lists."""
diff_html = difflib.HtmlDiff().make_file(list1, list2, left, right)
diff_html = re.sub(r'<title>.*</title>', '<title>%s</title>' % title, diff_html)
diff_html = diff_html.replace('content="text/html; charset=ISO-8859-1"',
'content="text/html; charset=UTF-8"')
diff_html = diff_html.encode('ascii', 'xmlcharrefreplace')
return diff_html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment