Skip to content

michaeljklein/pandoc_rb

 
 

Build Status

Gem Version

PandocRb

Like PandocRuby, but its interface is more limited:

module PandocRb
  def self.raise_exception(result)
  ..

  def self.convert(in_format_str, out_format_str, input_str, extract_media_path='')
  ..

  def self.reader_from_ext(extension)
  ..
end

The primary benefit is that instead of using system calls, pandoc_rb directly uses the memory allocated for Ruby Strings through the FFI.

The benchmark results indicate that both significant constant (from initialization) and linear (from streaming through bash pipes) overhead for PandocRuby is eliminated in pandoc_rb.

Installation

Requires Haskell-stack

Add this line to your application's Gemfile:

gem 'pandoc_rb'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install pandoc_rb

Usage

pandoc_rb's main interface is contained in the PandocRb module.

The public interface consists of constants and a main conversion function

The constants include:

PandocRb::Version # The current version
PandocRb::Readers # A list of allowed readers
PandocRb::Writers # A list of allowed writers

And the main conversion function is:

# General conversion function
PandocRb.convert input_format, output_format, input_string, (optional) extract_media_path

# Convert `markdown` to `latex`
PandocRb.convert 'markdown', 'latex', '_italic text_'

# Convert `docx` to `latex` from file
PandocRb.convert 'docx', 'latex', File.binread('some_doc.docx'), `extract/figures/dir`

# Convert `markdown` to `docx`, writing to a `docx` file
File.open 'some_doc.docx', 'wb' do |file|
  file.write PandocRb.convert('markdown', 'docx', '_italic text_')
end

Contributing

  1. Fork it ( https://github.com/michaeljklein/pandoc_rb/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Low level FFI bindings to Pandoc in Ruby

Topics

Resources

License

BSD-3-Clause, BSD-3-Clause licenses found

Licenses found

BSD-3-Clause
LICENSE
BSD-3-Clause
LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 49.0%
  • Ruby 42.9%
  • C 6.4%
  • TeX 0.9%
  • HTML 0.3%
  • Shell 0.3%
  • Roff 0.2%