https://github.com/alexandreruban/action-markdown
Markdown content editing for Ruby on Rails.
https://github.com/alexandreruban/action-markdown
markdown-editor ruby ruby-on-rails
Last synced: about 1 year ago
JSON representation
Markdown content editing for Ruby on Rails.
- Host: GitHub
- URL: https://github.com/alexandreruban/action-markdown
- Owner: alexandreruban
- License: mit
- Created: 2022-11-10T16:24:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T22:28:35.000Z (almost 2 years ago)
- Last Synced: 2025-03-30T05:09:37.177Z (about 1 year ago)
- Topics: markdown-editor, ruby, ruby-on-rails
- Language: Ruby
- Homepage:
- Size: 76.2 KB
- Stars: 147
- Watchers: 5
- Forks: 7
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: MIT-LICENSE
Awesome Lists containing this 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`:
```ruby
gem "action_markdown"
```
We can then run the installation script to copy the migration file:
```bash
bin/rails action_markdown:install
```
Last but not least, we need to run the migration:
```bash
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:
```rb
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:
```rb
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:
```erb
<%# articles/show.html.erb %>
<%= @article.content %>
```
In the view above, the Markdown content will automatically be converted to the following HTML:
```html
Title
This is a paragraph.
```
**Note**: To use a Markdown fields in forms, we should use the `markdown_field` helper like in the following example:
```erb
<%= 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](https://opensource.org/licenses/MIT).