New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement checkboxes? #323

Closed
alkrauss48 opened this Issue Nov 11, 2013 · 4 comments

Comments

Projects
None yet
4 participants
@alkrauss48
Copy link

alkrauss48 commented Nov 11, 2013

I recently added a custom checkbox parser on top of the existing markdown processing in redcarpet for a personal project, and wondered if you guys thought it would be worth adding to the gem. Here's a basic gist of the added code:

# pass in data attributes like method, remote, url
def render_with_checkboxes(text, data_options={})
  checkbox_regex  = /-\s?\[(x|\s)\]/
  text.gsub(checkbox_regex).with_index do |current_match, current_index|
    checked = current_match =~ /x/ ? true : false
    body = text.gsub(checkbox_regex).with_index do |match, index|
      if index == current_index
        checked ? "- [ ]" : "- [x]"
      else
        match
      end
    end
    check_box_tag "check_#{current_index}", "", checked, data: data_options
  end
  render(text)
end

This would turn - [ ], -[ ], - [x], and -[x] into respectively unchecked and checked checkboxes that have the power to send an instant server side request for whatever you want, and only modify the specific checkbox you selected in the overall updated attribute - similar to Github's checkboxes.

You could call it like:

@markdown.render_with_checkboxes("markdown text", { method: :put, remote: true, url: "some_url_with_an_updated_attribute"} )

I wrote this as if you had added this method to the Redcarpet::Markdown class. There are action_view dependencies with the check_box_tag. What's your guys' take on this? Is it best left out of the gem since it's not part of core markdown? And it's been a minute since I did C, but I'm pretty sure regex's are out of the question there.

@robin850

This comment has been minimized.

Copy link
Collaborator

robin850 commented Nov 11, 2013

Hello,

thanks for your proposal, this is a very nice snippet! ❤️

I'm not in favor of adding such kind of extensions directly in Redcarpet because there is still a lot and this is apparently quite straightforward to implement through callbacks. Also, I would advise you to rely on the list_item callback ; you can't pass a Hash of data attributes as your example show but you can customize the output so this is not really a problem.

However, this is very nice and this makes me think that we should maybe have a repository with user contributed extensions. What do you think @mattr- ? 😃

@mattr-

This comment has been minimized.

Copy link
Collaborator

mattr- commented Nov 12, 2013

I've been wondering about including GFM task lists in Redcarpet for sometime, but this is too heavyweight of an implementation.

As for a repository of user generated extensions, I'm not sure about that. I would say 80% of the pull requests I merge in Jekyll are for people adding plugins to the site's documentation. I don't want to maintain the same sort of thing for Redcarpet.

@parkr

This comment has been minimized.

Copy link

parkr commented Nov 12, 2013

@mattr- yeah don't go down that rabbit hole. 😆

@alkrauss48

This comment has been minimized.

Copy link
Author

alkrauss48 commented Nov 14, 2013

I definitely understand. Thanks for the feedback guys, I'll go ahead and close this issue then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment