Redcarpet 2 is written with sugar, spice and everything nice ============================================================ Redcarpet is Ruby library for Markdown processing that smells like butterflies and popcorn. Redcarpet used to be a drop-in replacement for Redcloth. This is no longer the case since version 2 -- it now has its own API, but retains the old name. Yes, that does mean that Redcarpet 2 is not backwards-compatible with the 1.X versions. Redcarpet is powered by the [Sundown](https://www.github.com/vmg/sundown) library. You might want to find out more about Sundown to see what makes this Ruby library so awesome. This library is written by people ------------------------------------------------------- Redcarpet 2 has been rewritten from scratch by Vicent Martí (@vmg). Why are you not following me on Twitter? 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. $ [sudo] gem install redcarpet The Redcarpet source (including Sundown as a submodule) 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 `Markdown` object is encouraged to be instantiated once with the required settings, and reused between parses. Markdown.new(renderer, extensions={}) Initializes a Markdown parser renderer - a renderer object, inheriting from Redcarpet::Render::Base. If the given object has not been instantiated, the library will do it with default arguments. extensions - a hash containing the Markdown extensions which the parser will identify. The following extensions are accepted: :no_intra_emphasis - do not parse emphasis inside of words. Strings such as `foo_bar_baz` will not generate `` tags. :tables - parse tables, PHP-Markdown style :fenced_code_blocks - parse fenced code blocks, PHP-Markdown style. Blocks delimited with 3 or more `~` or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block :autolink - parse links even when they are not enclosed in `<>` characters. Autolinks for the http, https and ftp protocols will be automatically detected. Email addresses are also handled, and http links without protocol, but starting with `www.` :strikethrough - parse strikethrough, PHP-Markdown style Two `~` characters mark the start of a strikethrough, e.g. `this is ~~good~~ bad` :lax_spacing - HTML blocks do not require to be surrounded by an empty line as in the Markdown standard. :space_after_headers - A space is always required between the hash at the beginning of a header and its name, e.g. `#this is my header` would not be a valid header. :superscript - parse superscripts after the `^` character; contiguous superscripts are nested together, and complex values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time` Example: markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true) 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 encourage reusability. Markdown#render(text) Render a Markdown document with the attached renderer text - a Markdown document Example: markdown.render("This is *bongos*, indeed.") #=> "

This is bongos, indeed

" Darling, I packed you a couple renderers for lunch -------------------------------------------------- Redcarpet comes with two built-in renderers, `Redcarpet::Render::HTML` and `Redcarpet::Render::XHTML`, which output HTML and XHTML, respectively. These renderers are actually implemented in C, and hence offer a brilliant performance, several degrees of magnitude faster than other Ruby Markdown solutions. All the rendering flags that previously applied only to HTML output have now been moved to the `Render::HTML` class, and may be enabled when instantiating the renderer: Render::HTML.new(render_options={}) Initializes an HTML renderer. The following flags are available: :filter_html - do not allow any user-inputted HTML in the output :no_images - do not generate any `` tags :no_links - do not generate any `` tags :no_styles - do not generate any `