Skip to content

A diff library that uses html tags to show differences between two strings of HTML.

License

Notifications You must be signed in to change notification settings

stackmystack/htmldiff

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTMLdiff

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!

Usage

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>'

Block tags

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.

Credits

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.

About

A diff library that uses html tags to show differences between two strings of HTML.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%