How to enable rdiscount extra markdown 'generate_toc' on Octopress

579 views Asked by At

I tried to make Octopress generate TOC with default markdown parser Rdiscount (2.1.7) by configuring _config.yml, but it didn't work and rake generate failed.
I tried answers in RDiscount :generate_toc with Sinatra, but it didn't work for me neither.
So I wonder if there's way to configure Octopress Rdiscount extra markdown syntax like this:

markdown: rdiscount
rdiscount: 
  extensions:
    - autolink
    - footnotes
    - smart
    - generate_toc

After set rdiscount in _config.yml and rake generate, I got an build error as follow:

sunnogo@a3e420:~/github/octopress$ rake generate
## Generating Site with Jekyll                                                                                                        
identical source/stylesheets/screen.css                                                                                               
Configuration from /home/sunnogo/github/octopress/_config.yml                                                                         
Building site: source -> public                                                                                                       
Liquid Exception: can't convert nil into String in atom.xml                                                                           
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/converters/markdown.rb:139:in `include?'                                            
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/converters/markdown.rb:139:in `convert'                                             
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/filters.rb:25:in `markdownify'                                                      
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/context.rb:58:in `invoke'                                                            
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:43:in `block in render'                                                  
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `each'                                                             
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `inject'                                                           
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `render'                                                           
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'                                                 
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:116:in `block (2 levels) in render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `each'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `each_with_index'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `block in render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/context.rb:91:in `stack'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:103:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:82:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/template.rb:124:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/template.rb:132:in `render!'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/convertible.rb:79:in `do_layout'
/home/sunnogo/github/octopress/plugins/post_filters.rb:167:in `do_layout'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/page.rb:100:in `render'
/home/sunnogo/github/octopress/plugins/category_generator.rb:100:in `write_category_index'
/home/sunnogo/github/octopress/plugins/category_generator.rb:111:in `block in write_category_indexes'
/home/sunnogo/github/octopress/plugins/category_generator.rb:110:in `each'
/home/sunnogo/github/octopress/plugins/category_generator.rb:110:in `write_category_indexes'
/home/sunnogo/github/octopress/plugins/category_generator.rb:139:in `generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:190:in `block in generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:189:in `each'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:189:in `generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:40:in `process'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/bin/jekyll:264:in `<top (required)>'
/usr/local/bin/jekyll:23:in `load'
/usr/local/bin/jekyll:23:in `<main>'
Build Failed
1

There are 1 answers

0
jorgenpt On

The problem you're seeing is due to a bug in Jekyll that has since been fixed. Specifically, Jekyll assumes that if you specify generate_toc then you also specify toc_token, which is the string you can write in your document to cause Jekyll to insert the table of contents.

An updated _config.yml would look like this:

markdown: rdiscount
rdiscount: 
  extensions:
    - autolink
    - footnotes
    - smart
    - generate_toc
  toc_token: "!TOC"

And then you would insert !TOC in your markdown document at the point where you want the table of contents to appear.