What is the best way to check for changes (edited/added/deleted text) in a post between two post's versions (original and edited one)?
I am using Markdown so I am not sure if using difflib.HtmlDiff is a good idea. My goal is to mark with a green background the added text and with a red background the deleted ones, something similar like what github does.
Try out
ghdiff
, GitHub style HTML for unified diffs. It's on PyPI, but there are better docs on GitHub currently. You'll need topip install ghdiff
.Simple usage, assuming the markdown is in
markdown1
andmarkdown2
.Here's a more explicit demonstration though. Let's say you have these two markdown strings:
We can perform a diff on these
When rendered, it looks like this:
Here's the raw and the rendered in an IPython Notebook: