https://github.com/tomasc/mongoid_markdown_extension
Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.
https://github.com/tomasc/mongoid_markdown_extension
Last synced: about 1 year ago
JSON representation
Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.
- Host: GitHub
- URL: https://github.com/tomasc/mongoid_markdown_extension
- Owner: tomasc
- License: mit
- Created: 2014-07-08T10:46:27.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-11-17T13:44:35.000Z (over 2 years ago)
- Last Synced: 2025-04-13T15:18:22.043Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 52.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Mongoid Markdown Extension
[](https://travis-ci.org/tomasc/mongoid_markdown_extension) [](http://badge.fury.io/rb/mongoid_markdown_extension)
[Mongoid](https://github.com/mongoid/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](https://github.com/vmg/redcarpet) library.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'mongoid_markdown_extension'
```
And then execute:
```sh
$ bundle
```
Or install it yourself as:
```sh
$ gem install mongoid_markdown_extension
```
## Configuration
The defaults are as follows:
```ruby
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`:
```ruby
MongoidMarkdownExtension::Markdown.configure do |c|
c.extensions = { autolink: true }
c.render_class = CustomRenderer
c.render_options = { filter_html: true }
end
```
See [Redcarpet documentation](https://github.com/vmg/redcarpet) for available extensions and render options.
## Usage
Add to a Mongoid model:
```ruby
class MyModel
include Mongoid::Document
field :text, type: MongoidMarkdownExtension::Markdown
end
```
Use it:
```Ruby
my_model.text = "*foo*"
my_model.text.to_html # => foo
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