Hi folks.

Just got through a couple scripts to open the current URL in Safari into 
BBEdit.  Then I inserted a quick Tidy directive to clean it up.  I review 
ugly pages.  

AppleScript: Current URL to BBEdit.scpt:

tell application "Safari" to set myU to the URL of the current tab in 
window 1
set alpha to "ruby 
/Users/YOURNAME/Library/Scripts/YOURSCRIPTS/BBEdit_Current_Page.rb '" & myU 
& "' | /usr/local/bin/bbedit" 
do shell script alpha
tell application "BBEdit" to activate



And the Ruby file: BBEdit_Current_Page.rb:

#!/usr/bin/ruby

require 'open-uri'
require 'nokogiri'

url = ARGV[0].to_s
page = Nokogiri::HTML(open(url))
pagestring = page.to_s

cmd = %w{ tidy --break-before-br no --char-encoding utf8 --clean yes 
--drop-empty-paras yes --force-output yes --indent yes --indent-spaces 2 
--join-classes yes --join-styles yes --markup yes --output-html yes --quiet 
yes --show-errors 0 --show-warnings no --sort-attributes alpha --tab-size 2 
--uppercase-attributes no --uppercase-tags no --vertical-space true --wrap 
0}

result = IO.popen(cmd, 'r+') {|io| 
  io.puts pagestring
  io.close_write
  io.read
}

puts result



Obviously, change the path to wherever your Ruby script is.  

Cheers








-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to