GithubHelp home page GithubHelp logo

sco11morgan / action-markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexandreruban/action-markdown

0.0 0.0 0.0 79 KB

Markdown content editing for Ruby on Rails.

License: MIT License

JavaScript 0.69% Ruby 74.00% CSS 13.64% HTML 11.67%

action-markdown's Introduction

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.

action-markdown's People

Contributors

alexandreruban avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.