This gem generates nice diff outputs (in HTML) from two supplied bits of HTML which are (presumably) partially different. It is aimed at the limited HTML that one would expect to be outputted from a WYSIWYG editor.
It is not foolproof and only gives good results with a limited (and not fully documented) range of HTML tags. See the specs for stuff that is known to work. Beyond that you're on your own!
doc_a = 'a word is here'
doc_b = 'a nother word is there'
HTMLDiff.diff(doc_a, doc_b)
# => 'a<ins class=\"diffins\"> nother</ins> word is <del class=\"diffmod\">here</del><ins class=\"diffmod\">there</ins>'
If you have some things which need to be treated as one unified lump of HTML
that has been added or taken away e.g. an embedded document composed of a div
with some images in it, then add class="block_tag"
to the opening div tag.
The diff will then surround the whole thing with an <ins>
or <del>
tag,
as well as showing the whole thing as replaced with a new version if any of
the content changes.
This is a fork of the htmldiff gem here https://github.com/myobie/htmldiff/ which appears to no longer be maintained. It has been refactored internally and made to be more useful when comparing the diff generated by HTML editors.