Markdown with table of contents

559 views
Skip to first unread message

Winston

unread,
Jan 20, 2012, 3:47:13 AM1/20/12
to nanoc
I'm looking for some help with Markdown processors. I'm trying to
convert a MoinMoin wiki to a static site generated by nanoc. I've
written some Python code to grab the wiki-format files and convert
them to Markdown. Now I'm trying to use nanoc to process the Markdown
to HTML.

My problem is that I'm having trouble finding a Markdown processor for
nanoc that can do the following:
- Fenced code blocks
- Syntax coloring using Pygments
- Generate a table of contents

I need Pygments for syntax coloring because coderay doesn't support R,
the language that the wiki is all about.

So far I've been using Redcarpet to do the Markdown processing. It
supports Pygments, but I can't figure out how to get it to generate a
TOC. The project page seems to say that its HTML renderer can generate
a TOC (with HTML_TOC) but I don't know how to make it work with nanoc.
I should also mention that I'm a total novice with Ruby...

It looks like Rdiscount can also use Pygments and possibly make a TOC,
but again, I'm not sure how to make the TOC work with nanoc.

Kramdown and Maruku don't seem to support Pygments, so they're out of
the running.


I'd appreciate any help in getting the TOC to work with Redcarpet or
Rdiscount. Thank you!
-Winston

Denis Defreyne

unread,
Feb 4, 2012, 2:02:35 AM2/4/12
to na...@googlegroups.com
Hi Winston,

This e-mail got stuck in the approval queue and I only noticed it today. Sorry!

The colorize_syntax filter that comes with nanoc allows specifying the language in a comment at the beginning of the code block. Also see http://nanoc.stoneship.org/docs/api/3.2/Nanoc3/Filters/ColorizeSyntax.html. For example:

#!ruby
def foo
puts "hello"
end

Syntax coloring can be done using pygments. You can pass the :default_colorizer => :pygmentize option to the filter to set the colorizer to be used for all languages (you can also specify a colorizer per language).

nanoc 3.2 does not have Redcarpet 2 support, but the master branch has a filter that is compatible with Redcarpet 2. With the new filter, you can pass :renderer => Redcarpet::Render::HTML_TOC to get a table of contents.

Alternatively, if you want a table of contents, you can roll your own TOC helpers. For the nanoc site, I use the following: https://github.com/ddfreyne/nanoc-site/blob/master/lib/helpers/toc.rb.

So, Kramdown and Maruku not having support for syntax coloring does not eliminate them; you just use nanoc’s more powerful syntax coloring filter. :)

Cheers,

Denis

> --
> You received this message because you are subscribed to the nanoc discusssion group.
>
> To post to this group, send email to na...@googlegroups.com
> To unsubscribe from this group, send email to
> nanoc+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nanoc?hl=en

Winston Chang

unread,
Feb 5, 2012, 12:43:57 PM2/5/12
to na...@googlegroups.com
Hi Denis -

Thanks for the help. I ended up using a different site generator (markdoc) for this project, but it's great to know that these things are possible with nanoc! In the future it's possible that I'll move over to nanoc since it seems more versatile, but I'll probably have to learn some more Ruby to get it to do what I want...

-Winston
Reply all
Reply to author
Forward
0 new messages