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#!/usr/bin/ruby
require 'open-uri'require 'nokogiri'
url = ARGV[0].to_spage = 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
Version 2: Checks if the file protocol is in use, and chops off any segment identifier
(function () {
var pgsrc ;
try {
pgsrc= window.frames[0].location.toString();
}
catch( err ) {
pgsrc = window.location.href ;
}
var file_loc = pgsrc.indexOf('file://') ;
if ( file_loc == 0 ) {
var segm_loc = pgsrc.indexOf('#');
if (segm_loc > 0 ) {
// we have a segment identifier on the end of the url.
var tmpS = pgsrc.substr(0,segm_loc) ;
pgsrc = tmpS ;
}
var twCmd = "txmt://open/?url="+pgsrc ;
window.open(twCmd ,"_self");
}
})();