新手问题 jruby 下去除 html 标签用什么

as181920 · January 11, 2013 · Last by jhjguxin replied at January 11, 2013 · 2270 hits

以前习惯用 sanitize,换到 jruby 环境(别问我为什么要用 jruby)下居然连内容都 clean 掉了,如下 irb(main):006:0> Sanitize.clean "

abc

" => " " irb(main):007:0>

有其它什么方便的安全的去除 html 标签的方法不

Nokogiri::HTML::DocumentFragment.parse(html).text 我自己先用这个了。

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html

include ActionView::Helpers::SanitizeHelper
html = "<a>1</a> <p>asdf</p>"
strip_tags(html)
You need to Sign in before reply, if you don't have an account, please Sign up first.