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

问题描述 投票:0回答:2

我正在尝试将nanoc 3.5.0与使用

pandoc
pandoc-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 不太熟悉,所以我目前的努力只是在黑暗中进行。

ruby pandoc nanoc
2个回答
5
投票

我删除了这个答案,以抗议 Stack Overflow 与 OpenAI 的合作关系。我不同意我的写作被用来训练生成式人工智能模型。


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提供了pandoc过滤器的改进版本,请检查:https://gist.github.com/xiaohanyu/9866531

© www.soinside.com 2019 - 2024. All rights reserved.