module Bergamasco::Pandoc

Constants

ALIAS_OPTIONS
ALLOWED_OPTIONS
AVAILABLE_OPTIONS

Options understood by pandoc, taken from pandoc.org/MANUAL.html. Ignore all other options passed to pandoc, unless overriden.

Public Class Methods

convert(text, options={}) click to toggle source
# File lib/bergamasco/pandoc.rb, line 25
def self.convert(text, options={})
  options = options.select { |k, v| ALLOWED_OPTIONS.include?(k.to_s.gsub('_', '-')) }.to_h

  options[:from] ||= :markdown
  options[:to] ||= :html

  PandocRuby.convert(text, options)
rescue Errno::ENOENT
  puts "Pandoc is not installed"
end
convert_to_jats(text, options={}) click to toggle source
# File lib/bergamasco/pandoc.rb, line 36
def self.convert_to_jats(text, options={})
  template = File.expand_path("../../../templates/default.jats", __FILE__)
  to = File.expand_path("../jats.lua", __FILE__)
  csl = File.expand_path("../jats.csl", __FILE__)

  options = options.merge(template: template, to: to, csl: csl)

  convert(text, options)
end
write_bibliograpy_to_yaml(bib_path, yaml_path) click to toggle source
# File lib/bergamasco/pandoc.rb, line 46
def self.write_bibliograpy_to_yaml(bib_path, yaml_path)
  yaml = `pandoc-citeproc --bib2yaml #{bib_path} 2>&1`
  return nil if $?.exitstatus > 0
  IO.write(yaml_path, yaml)
  SafeYAML.load(yaml)
end