Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (62 sloc) 2.16 KB
tidy: |-
Tidy Ruby Gem
If you're experiencing a Segmentation Fault (Rails app could not start)
List of Tidy-Ruby Options
libtidy is the backend of this gem.
Just replace hyphens with underscores.
For example,
show-warnings will be show_warnings
show-body-only will be show_body_only
# Do not use gem install tidy. It is outdated and buggy
# if you've done so already, do gem uninstall tidy and
# follow the directions below
$ git clone git://
$ cd tidy/
$ sudo ruby setup.rb
Rails app? make Tidy a dependency environment.rb
=========================================== do |config|
config.gem "tidy"
To install the gem on another machine,
run rake gems:install
Usage & Examples
require 'tidy'
# This might be required if your app is crashing.
# This is only available in the forked tidy.
# see Installation above
Tidy.fresh_tidy_version = true
Tidy.path = '/usr/lib/'
html = '<html><title>title</title>Body</html>'>true) do |tidy|
puts tidy.options.show_warnings # returns True
xml = tidy.clean(html) # See note below
puts tidy.errors # array
puts tidy.diagnostics # array
puts xml
Note: The code above will add a DOCTYPE, html, head, body tags where appropriate, if they do
not exist.
If you would like to check and clean an HTML SNIPPET, use these options:
opts = {
:show_warnings => true,
:show_body_only => true,
:doctype => 'omit',
:indent => true, # optional
} do |tidy|
puts tidy.clean(html)
diagnostics = tidy.diagnostics
errors = tidy.errors