Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Helpers around Markdown and Mustache
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app/helpers
lib
.gitignore
CHANGELOG.md
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
selectra_mustdown.gemspec

README.md

SelectraMustdown

SelectraMustdown offers two Rails helpers

Installation

Add the selectra gems source to your Gemfile :

source 'http://gems.selectra.info'

Then add the gem to your Gemfile :

gem 'selectra_mustdown'

Call bundle install to install it for your application.

markdown

This will render the given text through Markdown.

<%= markdown "**Hello World**" %>

Since version 0.1.0, Redcarper 2.x is used. You can customize the markdown behavior in two ways.

Configuration

Create an initializer like config/initializers/selectra_mdown.rb and use it to specify the Redcarpet options you want to use:

SelectraMustdown.configure do |config|
  # This is the list of Markdown extensions you want to use.
  # The complete list is available on https://github.com/tanoku/redcarpet
  # (Here are the defaults in SelectraMustdown)
  config.markdown_extensions = {
    no_intra_emphasis:  true,
    tables:             true,
    fenced_code_blocks: true,
    autolink:           true,
    strikethrough:      true
  }

  # These are the options of the HTML renderer you want to use.
  # The complete list is available on https://github.com/tanoku/redcarpet
  # (Here are the defaults in SelectraMustdown)
  config.renderer_options = {
    no_styles:        true,
    safe_links_only:  true
  }

  # You can use any renderer you want. Redcarpet's HTML is the default
  config.renderer = Redcarpet::Render::HTML
end

When calling the markdown helper

You can directly pass extensions and options to the markdown helper.

Be sure to note that the passed values are merged with the default ones. If you want to set a default value to false, pass it with false.

# First hash is the list of extensions, second one is the list of options
<%= markdown "**Hello World**", { autolink: false }, { hard_wrap: true} %>

mustdown

This one is a bit more complex. It uses the given text as a Mustache template and then renders the result through Markdown.

Given a @post object which has a title attribute :

<%= mustdown "**{{title}}**", @post %>

Since the mustdown helper is using the markdown helper under the hood, you can pass it additional hashed that will be forwarded to the markdown helper:

<%= mustdown "**{{title}}**", @post, { autolink: false }, { hard_wrap: true} %>
Something went wrong with that request. Please try again.