I just tried using the Ruby Tidy gem, the one hosted at Ruby Forge. Alas, its not compatible with Ruby 1.9.1:
': uninitialized constant DL::Importable (NameError) from /var/lib/gems/1.9.1/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:3:in ` ' from /var/lib/gems/1.9.1/gems/tidy-1.1.2/lib/tidy.rb:25:in `require' from /var/lib/gems/1.9.1/gems/tidy-1.1.2/lib/tidy.rb:25:in ` ' from /var/lib/gems/1.9.1/gems/tidy-1.1.2/lib/tidy.rb:21:in ` '
Thankfully, there is another Tidy Gem which is! As an added bonus, it uses the ffi gem. As a side note, the ffi gem is awesome!
It actually took some digging to find it, so here's a link to the github project:
And the author's website:
The docs are a bit sparse, so here's an example of how I'm using it:
TidyFFI::Tidy.new(output, :show_body_only => 1, :output_xml => 1, :numeric_entities => 1).clean
Basically, tidy options can be used when their hyphens (-) are switched with underscores (_).