Question

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.

Was it helpful?

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!)

OTHER TIPS

I've written a basic nanoc pandoc filter which calls pandoc directory without pandoc-ruby:

# All files in the 'lib' directory will be loaded
# before nanoc starts compiling.
# encoding: utf-8

module Nanoc::Filters

  class PandocSystem < Nanoc::Filter
    identifier :pandoc_system
    type :text => :text

    def run(content, params = {})
      if item[:extension] == 'org'
        `pandoc -f org -t html < #{item.raw_filename}`
      elsif ["md", "markdown"].index(item[:extension])
        `pandoc -f markdown -t html < #{item.raw_filename}`
      end
    end

  end

end

You can just pass your own options to pandoc according to item[:extension]. Hope it helps.


Update, I've create a new gist which provides an improved version of pandoc filter for nanoc, check: https://gist.github.com/xiaohanyu/9866531.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top