0.04
There's a lot of open issues
No release in over a year
Add rich text to your Ruby on Rails application thanks to Markdown.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 7.0.0
>= 0
 Project Readme

Welcome to ActionMarkdown

Do you like GitHub issues Markdown editor? I love it too! ActionMarkdown aims to provide the same feature out of the box for Rails applications. With ActionMarkdown, it is easy to write some Markdown text in a form field and convert it to HTML seamlessly in the view.

Installation

Let's add this line to our application's Gemfile:

gem "action_markdown"

We can then run the installation script to copy the migration file:

bin/rails action_markdown:install

Last but not least, we need to run the migration:

bin/rails db:migrate

ActionMarkdown is now installed, we are good to go!

Usage

Let's imagine we want to write articles in the Markdown format. In our Rails application, we will have an Article. To add Markdown content, we need to use the has_markdown macro like this:

class Article < ApplicationRecord
  has_markdown :content

  validates :content, presence: true
end

Without adding any new migration, we can now create a new article with Markdown text:

markdown = <<~MARKDOWN
# Title

This is a paragraph.
MARKDOWN

article = Article.create! content: markdown

In the view, the Markdown content will be converted to HTML. For example, in the ArticlesController#show view, we can render the content converted to HTML like this:

<%# articles/show.html.erb %>

<%= @article.content %>

In the view above, the Markdown content will automatically be converted to the following HTML:

<h1>Title</h1>
<p>This is a paragraph.</p>

Note: To use a Markdown fields in forms, we should use the markdown_field helper like in the following example:

<%= form_with model: article do |f| %>
  <%= f.label :content %>
  <%= f.markdown_field :content %>

  <%= f.submit "Save" %>
<% end %>

License

The gem is available as open source under the terms of the MIT License.