Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
#!/usr/bin/env ruby -wKU require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb' require 'erb' require 'open-uri' require 'net/http' def entity_escape(text) text.gsub(/&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)/, '&') end def make_link(text) case text when %r{\A(mailto:)?(.*?@.*\..*)\z}: "mailto:#{$2.gsub(/./) {sprintf("&#x%02X;", $&.unpack("U")[0])}}" when %r{http://www.(amazon.(?:com|co.uk|co.jp|ca|fr|de))/.+?/([A-Z0-9]{10})/[-a-zA-Z0-9_./%?=&]+}: "http://#{$1}/dp/#{$2}" when %r{\A[a-zA-Z][a-zA-Z0-9.+-]*://.*\z}: entity_escape(text) when %r{\A(www\..*|.*\.(com|uk|net|org|info))\z}: "http://#{entity_escape text}" when %r{\A.*\.(com|uk|net|org|info)\z}: "http://#{entity_escape text}" when %r{\A\S+\z}: entity_escape(text) else "http://some-site.com/" end end url = make_link %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip if url =~ /^http:\/\// and url != 'http://some-site.com/' eval 'title = fp.read.match(/<title>([^<>]*)<\/title>/i).to_a[1].strip rescue nil' if fp = open(url) rescue nil end input = STDIN.read print ERB.new(ENV['TM_LINK_FORMAT']).result
From the Design Piracy series on my blog: