Gollum: How to render task / checkboxes in Markdown format?

Created on 18 Jun 2015  路  10Comments  路  Source: gollum/gollum

I would like to see [ ] rendered as <input type="checkbox" readonly>.

Unfortunately github-markdown gem doesn't support rendering tasks. GitHub considers tasks as a part of their infrastructure (see https://github.com/github/markup/issues/208#issuecomment-24927799), so they are not rendered by GitHub::Markdown.

Forking the gem (https://rubygems.org/gems/github-markdown) is not trivial for me, as the renderer is written in C. Did anyone try to fork it and add this simple feature?

Most helpful comment

Whoa - I see! I'm in week 7 in my 24 week coding bootcamp and we've not gotten to Ruby yet. Seems the gem is a ruby thing. Maybe I should fake the boxes until I get there.

Then I'll come back to this thread and update the step-by-step process for newbies. Future Bon will be here soon...

All 10 comments

So far I'm using this monkeypatch:

module GitHub
  class Markdown
    def self.render(content)
      html = self.to_html(content, :markdown)
      html.gsub!('[ ]', '<input type="checkbox" readonly>')
      html.gsub!('[x]', '<input type="checkbox" checked="checked" readonly>')
      html
    end
  end
end

Thanks for sharing the monkeypatch, @marcinbiegun! However, I think this should really be an issue in one of the rendering gems (kramdown supports GFM and is gollum's default now), so closing for now.

@marcinbiegun how did you include that monkeypatch? I copied and pasted that code into config.rb and ran with the --config option but no results. Can you show you entire config.rb file?

@stsievert Probably doesn't work because github/markdown gem is loaded after your config.rb. Try to put require 'github/markdown' before the monkeypatch.

Hey y'all! I'm very late to the party, but hopefully I can get this going.

I'm brand new to github so I'm not sure where this config.rb is. Can anyone point me in that direction?

I'm going to google it now and if I find an answer, I'll post it for others like me.

@mathfour I'm not using Gollum anymore, but if I remember correctly I've patched my local gem files. You can find gem's directory by running gem open gollum, the config.rb file should be somewhere in subdirectories.

Thanks @marcinbiegun. I'm guessing I'll run that in my terminal? And that creates a file that will get updated to my github repository when I push it?

Whoa - I see! I'm in week 7 in my 24 week coding bootcamp and we've not gotten to Ruby yet. Seems the gem is a ruby thing. Maybe I should fake the boxes until I get there.

Then I'll come back to this thread and update the step-by-step process for newbies. Future Bon will be here soon...

@mathfour, config.rb is wherever you want it to be -- just pass the --config option to gollum on the command line (e.g. --config /path/to/your/config.rb). Unlike most other files in gollum, config.rb does not need to be committed in your repository, but it usually lives in the same directory as your repo (for convenience). Good luck with your ruby adventures!

I wonder if there is any way for this method to be extended to active checkboxes that write a change to the underlying file when checked or unchecked.
Perhaps there's a way to trigger a change using a custom javascript attached to the checkbox object.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

snhirsch picture snhirsch  路  4Comments

basking2 picture basking2  路  11Comments

bartkamphorst picture bartkamphorst  路  7Comments

jb2cool picture jb2cool  路  3Comments

scribu picture scribu  路  4Comments