Low commit activity in last 3 years
A long-lived project that still receives updates
Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.0
~> 3.4
 Project Readme

Mongoid Markdown Extension

Build Status Gem Version

Mongoid field extension that returns an object with to_html method returning the content converted from Markdown syntax to html. The Markdown conversion is done using the Redcarpet library.

Installation

Add this line to your application's Gemfile:

gem 'mongoid_markdown_extension'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_markdown_extension

Configuration

The defaults are as follows:

extensions = {
  autolink: true
  footnotes: true
  highlight: true
  space_after_headers: true
  strikethrough: true
  superscript: true
}

render_options = {}

These can be overwritten with an initializer, for example config/initializers/mongoid_markdown.rb:

MongoidMarkdownExtension::Markdown.configure do |c|
  c.extensions = { autolink: true }
  c.render_class = CustomRenderer
  c.render_options = { filter_html: true }
end

See Redcarpet documentation for available extensions and render options.

Usage

Add to a Mongoid model:

class MyModel
  include Mongoid::Document
  field :text, type: MongoidMarkdownExtension::Markdown
end

Use it:

my_model.text = "*foo*"

my_model.text.to_html # => <strong>foo</strong>
my_model.text.to_s # => *foo*

Contributing

  1. Fork it ( https://github.com/tomasc/mongoid_markdown_extension/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request