Post filter that runs HTML Tidy on the laid-out page to correct and clean up HTML in the output. This filter can be used with any of the asXXXX formats supported by Tidy.

Note that this filter requires the ‘tidy’ command, and should be added to the post_filters array, in contrast to most of the other filters which are page filters.

If ‘tidy’ isn‘t in your path you‘ll need to specify it here or via a TIDYCMD environment variable.

Methods
Attributes
[RW] format
[RW] tidycmd
[RW] tidyopts
Public Class methods
new(format = :xhtml, tidycmd = nil, tidyopts = '-q')

Create a new filter instance, using the specified output format, and optionally a custom ‘tidy’ command and options.

    # File lib/rote/filters/tidy.rb, line 27
27:       def initialize(format = :xhtml, tidycmd = nil, tidyopts = '-q') 
28:         @tidycmd = tidycmd || ENV['TIDYCMD'] || (PLATFORM =~ /mswin/ ? 'tidy.exe' : 'tidy')
29:           # TODO windows 'tidy.exe' correct?
30:           
31:         @tidyopts = tidyopts
32:         @format = format
33:       end
Public Instance methods
filter(text, page)
    # File lib/rote/filters/tidy.rb, line 37
37:       def filter(text, page)
38:         # TODO need to properly capture and log warnings here
39:         result = IO.popen("#{@tidycmd} #{self.tidyopts} -f tidy.log -as#{self.format}","r+") do |fp|
40:            Thread.new { fp.write(text); fp.close_write }
41:            fp.read
42:         end
43:         
44:         if $?.exitstatus < 2
45:           result
46:         else
47:           warn 'Tidy command failed (exitstatus: $?)'
48:           text
49:         end
50:       end