0

我想在 form.text_area 中使用 html & css :text

 <%= sanitize @post.text , tags: %w(table tr td div p span img), attributes: %w(id class style src) %>

但是 css attr "style" 不适用于背景图像。

<div style="color:red; background-image: url('http://tra-ta-ta.com/1.jpg')">
text 
</div>

图像不起作用。我如何使用背景图像?

sanitize.rb 中的问题

def sanitize_css(style) # disallow urls style = style.to_s.gsub(/url\s*\(\s*[^\s)]+?\s*\)\s*/, ' ')
4

2 回答 2

0

样式属性中的 URL 字符串 "url(...)" 被强制替换为 " " by HTML::WhiteListSanitizer,默认清理程序。您可以实现自己的清理程序,并通过编辑 config/application.rb 让 Rails 使用它。

config.action_view.white_list_sanitizer = MySpecialSanitizer.new

查看 ActionPack 中的以下文件以获取更多信息:

  • actionpack-x.x.x/lib/action_view/helpers/sanitize_helper.rb
  • actionpack-x.x.x/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
于 2012-12-08T14:38:10.930 回答
-2

我只使用未消毒的原料

于 2012-12-20T19:51:11.447 回答