Joe Dayvie
Joe Dayvie

Reputation: 314

Markdown gem for Rails

What is one of the best gems out there to implement markdown in user posts?

I am currently looking to allow users to edit their text via profiles, discussions, etc. and the simple_format solution is no longer suitable for me.

Upvotes: 2

Views: 937

Answers (2)

Robert Nubel
Robert Nubel

Reputation: 7522

RedCarpet is the Ruby community's usual go-to choice for implementing Markdown, though there are other options (Kramdown, for example).

To render your users' posts as Markdown with RedCarpet, you would write:

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true)
markdown.render(@post.content)

With Kramdown, the API is a bit simpler:

Kramdown::Document.new(@post.content).to_html

RedCloth does support a wealth of configuration options, though, which Kramdown does not.

Upvotes: 4

Related Questions