Giter Club home page Giter Club logo

markdown_checkboxes's Introduction

Markdown Checkboxes

This small, yet handy library sits on top of the Redcarpet markdown parser and adds checkbox rendering functionality simply by adding - [ ] or - [x] to your markdown (similar to how GitHub does it). To build a bare bones checkbox markdown parser:

require 'markdown_checkboxes'

parser = CheckboxMarkdown.new(Redcarpet::Render::HTML.new())

markdown = <<-MARKDOWN
# Test h1
### Test h3

* Top level list
  * Second level list

- [ ] Need to do
- [x] Done!
MARKDOWN

parser.render(markdown)

Parser

Here's the basic setup for defining your parser object:

# Initializes a Checkbox Markdown parser
CheckboxMarkdown.new(renderer, extensions = {})

You have many customizable options that you can pass in to your renderer and extensions. To see these options when declaring your parser, please view Redcarpet's main GitHub page. CheckboxMarkdown inherits from Redcarpet::Markdown, so the same constructor args will work.

Adding some serious checkbox action

Now, those checkboxes above will be visually built and clickable, but they won't actively send a request to the server to modify any data fields. To add some update action, throw in a block with some options like:

parser.render(markdown) do |data, updated_text|
  data.remote = true
  data.method = :put
  data.url = post_path(@post, post: { body: updated_text })
end

With the markdown_checkboxes DSL, you can set any attribute on the given data object, and it will get set client-side as an html 'data-(attribute)=(value)' attribute on the tag for your checkboxes. The DSL will also swap out underscores (_) for dashes (-) in your attribute names, so, for example, data.test_this will translate to "data-test-this"

The updated_text parameter that you get in the block will be the text that your body will get changed to, should that checkbox get clicked. You'll want to include this somewhere in a url attribute on the given data object.

Assuming you have your infrastructure set up accordingly, this should send an HTTP put request to your server to update your post's body, as well as fire unobtrusive javascript after the action is completed (allowing you to do things like prevent a page refresh, and other cool js things)

Installation

gem install markdown_checkboxes

Testing

rake test

markdown_checkboxes's People

Contributors

alkrauss48 avatar qrush avatar

Watchers

James Cloos avatar Ankeeth 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.