strip_tags(html)
public
Strips all HTML tags from the html,
including comments. This uses the html-scanner tokenizer and so its HTML parsing ability is limited by that of
html-scanner.
Show source
def strip_tags(html)
return html if html.blank?
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