繁体   English   中英

BlueCloth不支持Rails 3

[英]BlueCloth isn't working with Rails 3

BlueCloth与Rails 3兼容吗? 我不能让它工作,也许有人使用它?

在要求'bluecloth'之后,应该在视图中提供一个名为'markdown'的帮助器,但这似乎不可用。

我正在将应用程序升级到rails3,它对我来说很好。 我在模板中使用了一个名为“format”的辅助函数,虽然下面的代码也提供了markdown函数(在rails3中你必须使用raw())。 这是我的[project] /app/helpers/application_helper.rb的内容

module ApplicationHelper
  # Format text for display.                                                                    
  def format(text)
    sanitize(markdown(text))
  end

  # Process text with Markdown.                                                                 
  def markdown(text)
    BlueCloth::new(text).to_html
  end
end

就像之前的一张海报所说,你也需要

gem 'bluecloth'

在你的[project] / Gemfile中。 我的模板看起来像:

<p><%= format @post.body %></p>

使用降价功能,它将是:

<p><%= raw(markdown(@post.body)) %></p>

所以我使用格式化功能。 根据需要重命名功能。

我已经创建了一个新的Rails 3应用程序,并在Gemfile中添加了:

gem 'bluecloth', '>= 2.0.0'

然后打开控制台:

ruby-1.8.7-p302 > BlueCloth.new('**hello**').to_html
=> "<p><strong>hello</strong></p>"

所以它似乎正在起作用,至少对我而言。

您也可以尝试使用Rdiscount,但我认为它基于相同的C库,或者至少具有类似的基准。

你应该更具体地说明它是如何工作的:它会引发错误吗? 它不呈现HTML吗? 等等...

你可以做什么,而不是说它很漂亮,是在你的rails项目中创建一个初始化器并在其中加入以下内容:

require 'bluecloth'

class String
 def markdown
   BlueCloth.new(self).to_html
 end
end

这应该在每个字符串对象上启用markdown方法。

我建议通过BlueCloth切换到RDiscount。 这是一个替代品,并且在所有方面都更好。

http://github.com/rtomayko/rdiscount

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM