2013-02-01 37 views
3

我正在嘗試使用nanoc 3.5.0與使用pandoc-rubypandoc篩選器。具體地講,我無法從我的Rules文件傳遞幾個選項,使得以PandocRuby.convert()最後調用看起來是這樣的:nanoc:我如何將選項傳遞給pandoc-ruby?

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

第一指令導致紅寶石錯誤,第二個指令運行,但給了我一個空白頁,表明pandoc沒有得到所謂的權利。我對Ruby不太熟悉,所以我目前的努力只是在黑暗中刺探。

回答

5

nanoc自帶的pandoc過濾器無法正確地做到這一點。提供給過濾器的PARAMS通過直接傳遞給PandocRuby.convert

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

source

你的過濾器的調用有兩個以上的論點,這就是爲什麼它崩潰。過濾器肯定需要更新(我的想法如何被稱爲太天真)。如果您想要改善過濾器,歡迎您提交拉取請求!我同時報告了這個問題(link)。

(,希望我能儘快更新這個答案與正確的答案!)

+0

感謝您的快速響應!如果我理解了'pandoc-ruby'文檔,那麼第二個參數必須是'{:from => ...,:= => ...}'哈希值,其次是其他選項。我會嘗試更改當前的過濾器,但無法預測我是否成功。 – caracal

3

我寫了一個基本的nanoc pandoc過濾器調用pandoc目錄,而不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 

你可以只通過您自己根據item[:extension]選擇潘多哥。希望能幫助到你。


更新,我已經創建一個新的要點,提供pandoc過濾器的改進版本nanoc,請檢查:https://gist.github.com/xiaohanyu/9866531

+1

更新,這個問題已經由官方nanoc修復,查看:https://github.com/nanoc/nanoc/pull/433 –