tidy_ffi

I started tidy_ffi. It’s a Tidy bindings implemented via FFI gem. FFI is easy and fun.

Problems of current tidy gem.

There’s known bug with tidy API. On December 2006 tidy guys decided to change API, they had added allocator pointer in TidyBuf. So there’re two kinds of tidy libraries in the wild: without allocator (Mac OS X bundled one) and with allocator (newer version that can be found on linux and freebsd).

The second problem it doesn’t work with ruby 1.9. Ruby 1.9 came out with changed dl. FFI should provide ability to use tidy_ffi in rubinius and jruby as well.

Download

To install tidy_ffi type.

gem install tidy_ffi

And that’s it. Of course you need libffi installed, it’s not a gem. Mac OS X users have it installed, others should use distro tools to install it (apt-get, rpm whatever).

Usage

It’s quite easy too.

>> require ‘tidy_ffi’
=> true
>> TidyFFI::Tidy.new(‘test’).clean
=> “<!DOCTYPE html PUBLIC \”-//W3C//DTD HTML 3.2//EN\“>\n<html>\n<head>\n<meta name=\”generator\" content=\n\“HTML Tidy for Mac OS X (vers 31 October 2006 – Apple Inc. build 13), see www.w3.org\”>\n<title></title>\n</head>\n<body>\ntest\n</body>\n</html>\n"

There’s no way to get warnings yet. But several ways to change options for tidy.

More coming soon…