Rails 请问 Rails 有什么 gem 或方法可以去掉文本里的 html 标签呢?

whitecrow · December 04, 2012 · Last by as181920 replied at December 17, 2012 · 4401 hits

比如:< span style="color: rgb(68, 68, 68);">Selling isn< /span> 去掉后只剩下 Selling isn

.strip_html .strip_tags

#1 楼 @ywencn 非常感谢,使用 strip_tags 解决 :D

strip_tags strip_links sanitize

还有一个高级货

sanitize(html, options = {})
<%= sanitize @article.body, :tags => %w(table tr td), :attributes => %w(id class style) %>
Nokogiri::HTML('<span style="color: rgb(68, 68, 68);">Selling isn</span>').inner_text

#4 楼 @woaigithub 多谢,用这个解决了出现 &nbsp;的问题

#6 楼 @whitecrow 正则也可以去掉 html 标签的

You need to Sign in before reply, if you don't have an account, please Sign up first.