class Diffy::HtmlFormatter
def highlighted_words
def highlighted_words chunks = @diff.each_chunk. reject{|c| c == '\ No newline at end of file'"\n"} processed = [] lines = chunks.each_with_index.map do |chunk1, index| next if processed.include? index processed << index chunk1 = chunk1 chunk2 = chunks[index + 1] if not chunk2 next ERB::Util.h(chunk1) end dir1 = chunk1.each_char.first dir2 = chunk2.each_char.first case [dir1, dir2] when ['-', '+'] if chunk1.each_char.take(3).join("") =~ /^(---|\+\+\+|\\\\)/ and chunk2.each_char.take(3).join("") =~ /^(---|\+\+\+|\\\\)/ ERB::Util.h(chunk1) else line_diff = Diffy::Diff.new( split_characters(chunk1), split_characters(chunk2), Diffy::Diff::ORIGINAL_DEFAULT_OPTIONS ) hi1 = reconstruct_characters(line_diff, '-') hi2 = reconstruct_characters(line_diff, '+') processed << (index + 1) [hi1, hi2] end else ERB::Util.h(chunk1) end end.flatten lines.map{|line| line.each_line.map(&:chomp).to_a if line }.flatten.compact. map{|line|wrap_line(line) }.compact end