Skip to content

Extra Documentation

Francesco 'makevoid' Canessa edited this page Aug 21, 2025 · 1 revision

AI Generated Example usage (Claude Opus 4.1)

Configuration

RackTidyFFI accepts options to customize Tidy's behavior:

use RackTidyFFI, {
  # Tidy options
  indent: true,
  wrap: 80,
  'drop-font-tags' => true,
  'fix-bad-comments' => true
}

Common options:

  • indent: Auto-indent HTML (default: false)
  • wrap: Wrap lines at specified width (default: no wrapping)
  • output-xhtml: Output XHTML instead of HTML
  • show-warnings: Display validation warnings

Full Tidy options reference →

Sinatra

In your application file:

require 'sinatra'
require 'rack-tidy-ffi'

use RackTidyFFI

get '/' do
  '<html><body><p>Your HTML will be tidied!</body></html>'
end

Rack (config.ru)

require 'rack-tidy-ffi'

use RackTidyFFI
run YourApp
# config/application.rb
module YourApp
  class Application < Rails::Application
    # Tidy HTML in development and staging
    unless Rails.env.production?
      config.middleware.use RackTidyFFI, {
        indent: true,
        'show-warnings' => false
      }
    end
  end
end

Sinatra with Custom Options

# app.rb
require 'sinatra'
require 'rack-tidy-ffi'

configure :development do
  use RackTidyFFI, {
    indent: true,
    'output-xhtml' => true,
    'drop-empty-paras' => true
  }
end

get '/' do
  erb :index  # Your messy HTML will be cleaned!
end

Live Examples

Performance Considerations

RackTidyFFI processes HTML output on every request. Consider:

  • Development only - Enable only in development/staging environments
  • Caching - Use with page caching to minimize processing overhead
  • Selective routes - Apply only to specific routes if needed
# Apply only to HTML responses
use RackTidyFFI do |env|
  env['Content-Type'] =~ /html/
end

Troubleshooting

Installation Issues

If you encounter issues with tidy_ffi, ensure you have libtidy installed:

macOS:

brew install tidy-html5

Ubuntu/Debian:

sudo apt-get install libtidy-dev

RHEL/CentOS:

sudo yum install libtidy-devel