def diff(a, b)
if a == b
return a.deep_clone
end
if REXML::HashableElementDelegator === a and REXML::HashableElementDelegator === b
o = REXML::Element.new(a.name)
o.add_attributes a.attributes
hd = self.new(o)
Diff::LCS.traverse_balanced(a, b, hd)
o
elsif REXML::Text === a and REXML::Text === b
o = REXML::Element.new('span')
aa = a.value.split(/\s/)
ba = b.value.split(/\s/)
hd = XHTMLTextDiff.new(o)
Diff::LCS.traverse_balanced(aa, ba, hd)
o
else
raise ArgumentError.new("both arguments must be equal or both be elements. a is #{a.class.name} and b is #{b.class.name}")
end
end