Redcarpet

Categories: Coding Gems

Redcarpet is a gem used to interpret plain text Markdown syntax. Redcarpet is easy to use and can convert to HTML. Markdown is popularly used as format for readme files, or for writing messages in online discussion forums, or in text editors for the quick creation of rich text documents.

Extenal Links

Official Gem Documentation
https://github.com/vmg/redcarpet

GitHub Markdown Style Guide
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet

Examples

In ApplicationController.rb
helper_method :markdown

def markdown(text)
options = {
filterhtml: true,
hard
wrap: true,
linkattributes: { rel: 'nofollow' },
space
afterheaders: true,
fenced
code_blocks: true
}

extensions = {
autolink: true,
superscript: true,
disableindentedcode_blocks: true
}

renderer = Redcarpet::Render::HTML.new(options)
markdown = Redcarpet::Markdown.new(renderer, extensions)

markdown.render(text).html_safe
end

In any controller or view
text = "##Here is my text"
markdown(text)

Will return...
"Here is my text"

Contributing Users

andy, cara