BlueCloth与Rails 3兼容吗?我不能让它工作,也许有人在用它?
在需要'bluecloth‘之后,视图中应该有一个叫做'markdown’的帮助器可用,但这个似乎不可用。
发布于 2010-10-21 10:54:30
我现在正在将一个应用程序升级到rails3,它对我来说运行得很好。我在模板中使用了一个叫做"format“的辅助函数,尽管下面的代码也提供了一个markdown函数(在rails3中,你必须使用它和raw())。下面是我的项目/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'在您的项目/Gemfile中。我的模板如下所示:
<p><%= format @post.body %></p>使用markdown函数,它将是:
<p><%= raw(markdown(@post.body)) %></p>所以我使用了format函数。根据需要对函数进行重命名。
发布于 2010-09-27 17:40:01
我创建了一个新的Rails 3应用程序,并在Gemfile中添加了:
gem 'bluecloth', '>= 2.0.0'然后打开控制台:
ruby-1.8.7-p302 > BlueCloth.new('**hello**').to_html
=> "<p><strong>hello</strong></p>"所以它似乎起作用了,至少对我来说是这样。
你也可以尝试Rdiscount,我不是shure,但我认为它基于相同的C库,或者至少有类似的基准测试。
您应该更具体地说明它是如何不工作的:它会引发错误吗?它不会呈现html吗?等等。
发布于 2010-10-03 21:56:42
你可以做的,不是说它很漂亮,而是在你的rails项目中创建一个初始化器,并在其中放入以下内容:
require 'bluecloth'
class String
def markdown
BlueCloth.new(self).to_html
end
end这将在每个string对象上启用markdown方法。
https://stackoverflow.com/questions/3602040
复制相似问题