Last active
August 29, 2015 14:07
-
-
Save jaredks/1a17bf34c520aefa7dda to your computer and use it in GitHub Desktop.
Create html diff of two given lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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