rubypandocnanoc

nanoc: How can I pass options to pandoc-ruby?


I'm trying to use nanoc 3.5.0 with the pandoc filter that uses pandoc-ruby. Specifically, I'm not able to pass several options from my Rules file such that the final call to PandocRuby.convert() looks like this:

PandocRuby.convert(content,
                   {:from => :markdown, :to => :html}, :no_wrap, 
                   :table_of_contents, :mathjax, :standalone,
                   {"template" => Dir.getwd + '/layouts/pandocTemplate.html'})

When I place the above call in a custom filter, everything works fine. However, I would like to specify pandoc options in Rules such that I don't have to create a special filter for every set of options.

The default pandoc filter is defined as the function run(content, params={}) and simply calls PandocRuby.convert(content, params). How can I set params such that PandocRuby.convert() gets called correctly? The following directives in Rules do not work:

filter :pandoc, :params => { :from => :markdown, :to => :html, :no_wrap, :table_of_contents, :mathjax, :standalone, "template" => Dir.getwd + '/layouts/pandocTemplate.html' }
filter :pandoc, :params => { :from => :markdown, :to => :html, :no_wrap => true, :table_of_contents => true, :mathjax => true, :standalone => true, "template" => Dir.getwd + '/layouts/pandocTemplate.html' }

The first directive results in a Ruby error, the second directive runs but gives me a blank page, indicating that pandoc did not get called right. I'm not really familiar with Ruby, so my current efforts are just stabs in the dark.


Solution

  • The pandoc filter that comes with nanoc can’t properly do that at this point. The params given to the filter are passed through directly to PandocRuby.convert:

    def run(content, params={})
      PandocRuby.convert(content, params)
    end
    

    (source)

    Your invocation of the filter has more than two arguments, which is why it crashes. The filter certainly needs to be updated (My idea of how it could be called was too naïve). If you want to take a shot at improving the filter, you are certainly welcome to submit a pull request! I have reported this as an issue in the mean time (link).

    (And hopefully I can update this answer with a proper answer soon!)