尝试在 haml-rails 中使用 :markdown 过滤器时“没有这样的文件或目录 - pandoc”

‘No such file or directory - pandoc’ when trying to use :markdown filter in haml-rails

我正在尝试在 Rails 5.0.2 上使用 :markdown filter with haml-rails

当我第一次尝试在 HAML 文件中使用 Markdown 时,它说它需要 pandoc-ruby 作为依赖项,所以我将其添加到我的 Gemfile 中。但是,现在当我尝试在我的文件中使用 :markdown 时,出现以下错误:

来自its README

PandocRuby is a wrapper for Pandoc, a Haskell library with command line tools for converting one markup format to another.

需要单独安装Pandoc(强调):

First, make sure to install Pandoc.

Next, add PandocRuby to your Gemfile

gem 'pandoc-ruby'

这里你不需要 Pandoc,这只是 Tilt 尝试使用的第一个降价处理器,如果找不到其他处理器就会报告。不过你确实需要一些降价处理器。

最简单的解决方法可能是从 Gemfile 中删除 pandoc-ruby 并添加 Ruby 降价处理器(例如 kramdown)。

如果你需要更多地控制 Haml 使用的处理器(例如,如果你想对 Haml 过滤器使用 kramdown,但在你的应用程序中有 RedCarpet 用于其他东西),请在初始化程序中尝试这样的事情:

require 'tilt/kramdown'
module Haml::Filters
  remove_filter("Markdown")
  register_tilt_filter "Markdown", :template_class => Tilt::KramdownTemplate
end

如果您确实想使用 Pandoc 来呈现 markdown,那么您需要确保它已安装,请参阅