Skip to content

vmg/redcarpet

Repository files navigation

Redcarpet is written with sugar, spice and everything nice

Build status Help Contribute to Open Source Gem Version

Redcarpet is a Ruby library for Markdown processing that smells like butterflies and popcorn.

This library is written by people

Redcarpet was written by Vicent Martí. It is maintained by Robin Dupret and Matt Rogers.

Redcarpet would not be possible without the Sundown library and its authors (Natacha Porté, Vicent Martí, and its many awesome contributors).

You can totally install it as a Gem

Redcarpet is readily available as a Ruby gem. It will build some native extensions, but the parser is standalone and requires no installed libraries. Starting with Redcarpet 3.0, the minimum required Ruby version is 1.9.2 (or Rubinius in 1.9 mode).

$ [sudo] gem install redcarpet

If you need to use it with Ruby 1.8.7, you will have to stick with 2.3.0:

$ [sudo] gem install redcarpet -v 2.3.0

The Redcarpet source is available at GitHub:

$ git clone git://github.com/vmg/redcarpet.git

And it's like really simple to use

The core of the Redcarpet library is the Redcarpet::Markdown class. Each instance of the class is attached to a Renderer object; the Markdown class performs parsing of a document and uses the attached renderer to generate output.

The Redcarpet::Markdown object is encouraged to be instantiated once with the required settings, and reused between parses.

# Initializes a Markdown parser
markdown = Redcarpet::Markdown.new(renderer, extensions = {})

Here, the renderer variable refers to a renderer object, inheriting from Redcarpet::Render::Base. If the given object has not been instantiated, the library will do it with default arguments.

Rendering with the Markdown object is done through Markdown#render. Unlike in the RedCloth API, the text to render is passed as an argument and not stored inside the Markdown instance, to