nanoc:我如何将选项传递给pandoc-ruby?

时间:2013-02-01 12:52:01

标签: ruby pandoc nanoc

我正在尝试将nanoc 3.5.0与使用pandocpandoc-ruby过滤器一起使用。具体来说,我无法从Rules文件中传递多个选项,以致最终调用PandocRuby.convert()如下所示:

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

当我将上述调用放在自定义过滤器中时,一切正常。但是,我想在Rules中指定pandoc选项,这样我就不必为每组选项创建一个特殊的过滤器。

默认的pandoc过滤器定义为函数run(content, params={}),只需调用PandocRuby.convert(content, params)即可。如何设置params以便正确调用PandocRuby.convert()Rules中的以下指令不起作用:

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' }

第一个指令导致Ruby错误,第二个指令运行但是给我一个空白页面,表明pandoc没有被调用。我对Ruby并不熟悉,所以我目前的努力只是在黑暗中刺伤。

2 个答案:

答案 0 :(得分:5)

此时,nanoc附带的pandoc过滤器无法正常执行此操作。给过滤器的参数直接传递给PandocRuby.convert

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

source

您对过滤器的调用有两个以上的参数,这就是它崩溃的原因。过滤器肯定需要更新(我对如何调用它的想法太天真了)。如果您想改进过滤器,我们欢迎您提交拉动请求!我在同一时间(link)报告了这个问题。

(希望我能尽快用适当的答案更新这个答案!)

答案 1 :(得分:3)

我编写了一个基本的nanoc pandoc过滤器,它在没有pandoc-ruby的情况下调用pandoc目录:

# 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

您可以根据item[:extension]将自己的选项传递给pandoc。希望它有所帮助。


更新,我创建了一个新的要点,为nanoc提供了改进版本的pandoc过滤器,请检查:https://gist.github.com/xiaohanyu/9866531