Skip to content

Commit

Permalink
Improved HTML Tidy command with error handling
Browse files Browse the repository at this point in the history
git-svn-id: http://macromates.com/svn/Bundles/trunk/Bundles/HTML.tmbundle@8226 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
ciaran committed Sep 26, 2007
1 parent 20d4d86 commit 39d05c4
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions Commands/Tidy.plist
Expand Up @@ -9,26 +9,63 @@
<key>capturePattern</key>
<string>line (\d+) column (\d+) - (.*?)$</string>
<key>command</key>
<string>"${TM_TIDY:-tidy}" -f /dev/null -iq -utf8 \
-wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
${TM_SELECTED_TEXT:+--show-body-only yes} \
${TM_XHTML:+-asxhtml} \
--doctype strict \
--enclose-text yes \
--tidy-mark no|\
if [[ "$TM_SOFT_TABS" == "YES" ]]; then cat; else ruby -pe '
unless $in_pre
tab_size = ENV["TM_TAB_SIZE"].to_i
space, text = /( *)(.*)/m.match($_)[1..2]
$_ = "\t" * (space.length / tab_size).floor +
" " * (space.length % tab_size) + text
end
$in_pre = true if(/&lt;pre&gt;/)
$in_pre = false if(/&lt;\/pre&gt;/)
'
fi</string>
<string>#!/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 &lt;!DOCTYPE&gt; declaration') or line.include?("Warning: inserting missing 'title' element")))
end.join rescue nil
unless log.empty?
options = {
:title =&gt; "Tidy Warnings",
:summary =&gt; "Warnings for tidying your document (press escape to close):",
:log =&gt; 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?("&lt;pre&gt;")
in_pre = false if line.include?("&lt;/pre&gt;")
end
end</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
Expand Down

0 comments on commit 39d05c4

Please sign in to comment.