Module: Yaml::Converter::Renderer::PandocShell
- Defined in:
- lib/yaml/converter/renderer/pandoc_shell.rb
Overview
Shells out to pandoc to convert markdown to target format.
Provides lightweight detection of pandoc and execution with arbitrary arguments.
Class Method Summary collapse
-
.render(md_path:, out_path:, pandoc_path: nil, args: []) ⇒ Boolean
Invoke pandoc to convert markdown file to another format.
-
.which(cmd) ⇒ String?
Locate an executable in the current PATH.
Class Method Details
.render(md_path:, out_path:, pandoc_path: nil, args: []) ⇒ Boolean
Invoke pandoc to convert markdown file to another format.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/yaml/converter/renderer/pandoc_shell.rb', line 40 def render(md_path:, out_path:, pandoc_path: nil, args: []) bin = pandoc_path || which("pandoc") return false unless bin cmd = [bin] + args + ["-o", out_path, md_path] _stdout, stderr, status = Open3.capture3(*cmd) unless status.success? warn("pandoc failed: #{stderr}") return false end true end |
.which(cmd) ⇒ String?
Locate an executable in the current PATH.
21 22 23 24 25 26 27 |
# File 'lib/yaml/converter/renderer/pandoc_shell.rb', line 21 def which(cmd) ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| exe = File.join(path, cmd) return exe if File.executable?(exe) end nil end |