Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlueCloth isn't working with Rails 3

Is BlueCloth compatible with Rails 3? I can't make it work, maybe someone uses it?

There is supposed to be a helper called 'markdown' available in the views after requiring 'bluecloth', but this doesn't seem to be available.

like image 448
user425766 Avatar asked Aug 30 '10 15:08

user425766


2 Answers

I'm upgrading an app to rails3 right now and it worked fine for me. I use a helper function called "format" in templates though the code below also provides a markdown function (in rails3 you'll have to use that with raw()). Here's the contents of my [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

Like a previous poster said, you'll also need

gem 'bluecloth'

in your [project]/Gemfile. My template looks like:

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

With the markdown function it would be:

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

So I use the format function. Rename the functions however you want.

like image 123
Mike Howsden Avatar answered Nov 11 '22 13:11

Mike Howsden


I've created a fresh Rails 3 app and in the Gemfile I added:

gem 'bluecloth', '>= 2.0.0'

Then opened the console:

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

So it appears to be working, at least for me.

You could also try Rdiscount which I am not shure but I think is based on the same C library, or at least has similar benchmarks.

You should be more specific in how is it not working: Does it raises an error? Doesn't it renders html? etc...

like image 2
Macario Avatar answered Nov 11 '22 12:11

Macario