[TxMt] Re: Configuring HTML Tidy

3zzy iaezzy at gmail.com
Mon Sep 14 17:14:39 UTC 2009


Thanks Steve, but I'm not sure what to change in that code snippet, following
is the full command source:

#!/usr/bin/env ruby -wKU

require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'

result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
          -wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
		--indent yes \
          ${TM_XHTML:+-asxhtml --output-xhtml yes} \
          ${TM_SELECTED_TEXT:+--show-body-only yes} \
          --enclose-text yes \
          --doctype strict \
		--wrap-php no \
          --tidy-mark no`
status = $?.exitstatus

at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log

if status == 2 # Errors

  msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
  TextMate.exit_show_tool_tip msg

elsif status == 1 # Warnings - use output but also display notification with
warnings
  
  log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
    ! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing
<!DOCTYPE> declaration') or line.include?("Warning: inserting missing
'title' element")))
  end.join rescue nil
  
  unless log.empty?
    options = {
      :title   => "Tidy Warnings",
      :summary => "Warnings for tidying your document (press escape to
close):",
      :log     => log
    }
    TextMate::UI.simple_notification(options)
  end

end

if ENV['TM_SOFT_TABS'] == "YES"
  print result
else
  in_pre = false
  result.each_line do |line|
    unless in_pre
      tab_size = ENV["TM_TAB_SIZE"].to_i
      space, text = /( *)(.*)/m.match(line)[1..2]
      line = "\t" * (space.length / tab_size).floor + " "  * (space.length %
tab_size) + text
    end
    
    print line
  
    in_pre = true  if line.include?("<pre>")
    in_pre = false if line.include?("</pre>")
  end
end 

Thanks for any help you can offer.



Steve King-8 wrote:
> 
> Ibrahim Ezzy wrote:
>> Not really. I manually indent where possible, but Tidy is required for
>> tidying up someone else's files with hundreds of lines of code.
> 
> My solution to this sort of thing is to run Tidy, then follow up with a
> regex replacement.  In your case I'd do something like...
> 
> Find:  <li>\n\s*(.*)\n\s*</li>
> Replace: <li>$1</li>
> 
> This should pull out the newlines and extraneous spaces.
> 
> Kind of clumsy, but I suppose you could make a macro to do all this in
> one keystroke if you need to do the same thing frequently.
> 
> -- 
> Steve King
> Sr. Software Engineer
> Arbor Networks
> +1 734 821 1461
> www.arbornetworks.com <http://www.arbornetworks.com/>
> 
> 
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
> 
> 

-- 
View this message in context: http://www.nabble.com/Configuring-HTML-Tidy-tp25420981p25439752.html
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list