Markdown in Rails with Redcarpet

Why it’s awesome

Redcarpet is an extremely quick way to show Markdown as formatted HTML in your Ruby / Rails app.

Markdown is a simple way to format text. Think of it as an easier version of HTML.

In Markdown, this:

Becomes this:

Hello, this is bold and this is italic.

Users can enter Markdown into regular text fields, and you can store it as text in your database. Then, with Redcarpet, you can render the Markdown as HTML.

You might allow users to comment within your app using regular text or Markdown, and then show those comments with formatting.

Quick start

Add this to your Gemfile:

Store Markdown in a regular text field within your database. To the user, you can present a plain text field and link to a Markdown quick reference.

Once some Markdown is in your database, you can convert it to HTML in your controller…

… then show the resulting HTML in a view:

In the example above, we used the body of a comment as an example.

Check out the documentation and this video overview.

In closing

I love Markdown, and will use this tool whenever I need to maintain static, formatted content in my app.

Rolling out Markdown editing to end users is trickier, since many may not be familiar with it. However, allowing people to use Markdown is different from requiring it. If you allow Markdown in comments, for instance, place a note under your new comment field stating that Markdown is an option, and link to a quick reference.

The Up and Running series

This is part of the Up and Running series, showing you how to jump onboard to useful developer tools. Hear about what’s coming next by joining our e-mail list. brings Rails job offers to you. Free for candidates. Salaries from $75,000 to $250,000. Sign up now!

4 thoughts on “Markdown in Rails with Redcarpet”

Leave a Reply