strip_tags(html)
public
Strips all HTML tags from the input, including
comments. This uses the html-scanner tokenizer and so it’s HTML parsing ability is limited by that of
html-scanner.
Returns the tag free text.
Show source
def strip_tags(html)
if html.index("<")
text = ""
tokenizer = HTML::Tokenizer.new(html)
while token = tokenizer.next
node = HTML::Node.parse(nil, 0, 0, token, false)
text << node.to_s if node.class == HTML::Text
end
text.gsub(/<!--(.*?)-->[\n]?/m, "")
else
html
end
end