Ruby on rails Rails-Redcloth,如何转换现有的wysiwyg垃圾html?

Ruby on rails Rails-Redcloth,如何转换现有的wysiwyg垃圾html?,ruby-on-rails,rubygems,redcloth,Ruby On Rails,Rubygems,Redcloth,我看到了曙光,我正在将我的网站转换为使用美妙的纺织品标记 问题是,我的数据库中有几年的html内容不是纺织品标记。我如何把它转换成纺织品?有非人工方式吗 如果没有,在输出内容时,我是否应该检查html,如果存在,则不使用红布 例如: // not sure of best way to check if a string has html if (@content.description has html) <%= @content.description.html_safe %&

我看到了曙光,我正在将我的网站转换为使用美妙的纺织品标记

问题是,我的数据库中有几年的html内容不是纺织品标记。我如何把它转换成纺织品?有非人工方式吗

如果没有,在输出内容时,我是否应该检查html,如果存在,则不使用红布

例如:

// not sure of best way to check if a string has html
if (@content.description has html)
    <%= @content.description.html_safe %>
else
    <%= RedCloth.new(@content.description).to_html %>
end
//不确定检查字符串是否包含html的最佳方法
如果(@content.description有html)
其他的
结束

红宝石是怎么做的?帮助一个新手!:-)

我正在使用RDisont进行标记解析,它可以处理html和文本输入。 我想纺织品允许html,事实上,如果我在这个编辑器中放置strong标记,它就是工作

如果用redcloth简单地解析html和textile,会发生什么

<%= RedCloth.new(@content.description).to_html %>

找到了以下内容:

这是:

这是:

编辑

我选择了html2textile。我按照我要求的说明安装了它

然后,我在/lib/tasks/app.rake中创建了一个名为textile_-ize的任务。看起来是这样的:

namespace :db do
  desc "Convert html to textile on desc columns"
  task :textile_ize => :environment do
    puts "Starting Desc"

    contents = Content.all
    contents.each do |c|
                    #desc
        parser = HTMLToTextileParser.new
        parser.feed(c.desc)
        c.desc_textile = parser.to_textile
        c.save
    end

    puts "Finished with Desc"

end
然后我可以运行rake db:textile\u ize并poof,done。实际上,我添加了一个额外的列来存储纺织品,并使用
:before\u save
从纺织品创建html。(在我的模型中)看起来是这样的:


希望这有助于其他人

它增加了两倍的空格,因为它还将断行检测为段落:/
before_save :textile_ize

# convert textile to html
def textile_ize
    self.desc = RedCloth.new(self.desc_textile).to_html     
end