我要找的意见如何清洁提交HTML的Web应用程序,因此可以在未来进行风格或未关闭标签冲倒一个应用程序的布局重新显示。

在我的应用程序丰富的HTML是通过与YUI富文本编辑器,它默认运行几个正则表达式来清洁输入用户提交的,而且我还调用[filter_MSWord][1]赶上从办公室发送的任何废话

在后端,我跑ruby-tidy被显示为注释前消毒的HTML,但有时不好粘贴HTML仍然会影响我使用的应用程序的布局 - 我该如何防范呢?

FWIW这里是我使用的消毒剂设置 -

module HTMLSanitizer


  def tidy_html(input)

    cleaned_html = Tidy.open(:show_warnings=>false) do |tidy|
      # don’t output body and html tags
      tidy.options.show_body_only = true 
      # output xhtml
      tidy.options.output_html = true
      # don’t write newlines all over the place
      tidy.options.wrap = 0
      # use utf8 to play nice with rails
      tidy.options.char_encoding = 'utf8'
      xml = tidy.clean(input)
      xml
    end
  end

end

还有什么是我选择这里?

有帮助吗?

解决方案

我个人使用的sanitize宝石。

require 'sanitize'
op = Sanitize.clean("<html><body>wow!</body></hhhh>") # Notice the incorrect HTML. It still outputs "wow!"

其他提示

我使用购自ActionView所述的sanitize辅助

模块::的ActionView助手:: SanitizeHelper

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top