Making Diffy a little less creative

December 08, 2010

I just pushed a new version of my Diffy ruby gem.

This version does a better job when highlighting parts of lines in the html diff output.

Ward Cunningham pointed out to me that sometimes Diffy would get a little creative when finding similarities in between lines. For example, while technically correct Diffy 2.0.0 could come off as a bit of a know-it-all when it found one letter similarities between “Unescaped” and “Swallowed”.

  • ==Links around Images==
  • Images should link to absolute paths like ’/File:Picture.jpg’ instead of relative links (i.e. ‘File:Picture.jpg’).
  • The later confuses my browser and causes it to link to file:///Picture.jpg, which won’t work at all.
  • ==Unescaped html in nowiki tags==
  • ==Swallowed html in nowiki tags==
  • The break tag in here is rendered.
  • The break tag in here is not rendered as literal text despite being in nowiki and code tags. This differs from mediawiki’s behavior.
  • “To create a line break put this <code><nowiki><br /></nowiki></code> in your markup.”

Version 2.0.1 suppresses this creativity a little bit for clearer output:

  • ==Links around Images==
  • Images should link to absolute paths like ’/File:Picture.jpg’ instead of relative links (i.e. ‘File:Picture.jpg’).
  • The later confuses my browser and causes it to link to file:///Picture.jpg, which won’t work at all.
  • ==Unescaped html in nowiki tags==
  • ==Swallowed html in nowiki tags==
  • The break tag in here is rendered.
  • The break tag in here is not rendered as literal text despite being in nowiki and code tags. This differs from mediawiki’s behavior.
  • “To create a line break put this <code><nowiki><br /></nowiki></code> in your markup.”

The easiest way to diff two strings in ruby

November 26, 2010

I just released version 2.0 of Diffy.

I wanted to make it dead simple to generate attractive diff output from within a ruby application.

Here’s how you use it:

$ sudo gem install diffy
$ irb
>> string1 = <<-TXT
>" Hello how are you
>" I'm fine
>" That's great
>" TXT
=> "Hello how are you\nI'm fine\nThat's great\n" 
>> string2 = <<-TXT
>" Hello how are you?
>" I'm fine
>" That's swell
>" TXT
=> "Hello how are you?\nI'm fine\nThat's swell\n" 
>> puts Diffy::Diff.new(string1, string2)
-Hello how are you
+Hello how are you?
 I'm fine
-That's great
+That's swell

It also will generate nice html for you:

>> Diffy::Diff.new(string1, string2).to_s(:html)
  • We were all having a good time.
  • Soon it was very late.
  • Time flies like an arrow” said I.
  • Fruit flies like a banana” I said.
  • Then I left.

You can find out more in the README