/ Published in: Ruby
This replaces the PHP-based function in the HTML bundle. You need to add two files to your bundle's Support/lib folder (create the directories if they're not present):
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb?format=raw
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb?format=raw
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/vendor/html-scanner/html/node.rb?format=raw
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/vendor/html-scanner/html/tokenizer.rb?format=raw
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby -w require ENV['TM_BUNDLE_SUPPORT'] + "/lib/tokenizer.rb" require ENV['TM_BUNDLE_SUPPORT'] + "/lib/node.rb" def strip_tags(html) return html if html.empty? || !html.include?('<') output = "" tokenizer = HTML::Tokenizer.new(html) while token = tokenizer.next node = HTML::Node.parse(nil, 0, 0, token, false) output += token unless (node.kind_of? HTML::Tag) or (token =~ /^<!/) end return output end print strip_tags(STDIN.read)