-
Notifications
You must be signed in to change notification settings - Fork 3
Extra Documentation
Francesco 'makevoid' Canessa edited this page Aug 21, 2025
·
1 revision
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
In your application file:
require 'sinatra'
require 'rack-tidy-ffi'
use RackTidyFFI
get '/' do
'<html><body><p>Your HTML will be tidied!</body></html>'
endrequire '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# 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!
endRackTidyFFI 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/
endIf you encounter issues with tidy_ffi, ensure you have libtidy installed:
macOS:
brew install tidy-html5Ubuntu/Debian:
sudo apt-get install libtidy-devRHEL/CentOS:
sudo yum install libtidy-devel