Return to Snippet

Revision: 2340
at February 2, 2007 15:31 by gtcaz


Updated Code
#!/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)

Revision: 2339
at February 2, 2007 15:28 by gtcaz


Initial Code
#!/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)

Initial URL


Initial Description
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

Initial Title
Strip HTML Tags

Initial Tags
command, textmate, html

Initial Language
Ruby