• Stars
    star
    330
  • Rank 122,908 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby wrapper for Pandoc

PandocRuby

Build Status Gem Version Gem Downloads

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

Pandoc can convert documents from a variety of formats including markdown, reStructuredText, textile, HTML, DocBook, LaTeX, and MediaWiki markup to a variety of other formats, including markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages, HTML slide shows, EPUB, Microsoft Word docx, and more.

Installation

First, install Pandoc.

PandocRuby is available on RubyGems:

gem install pandoc-ruby

To install with Bundler, add the following to your Gemfile:

gem 'pandoc-ruby'

Then run bundle install

Usage

require 'pandoc-ruby'
@converter = PandocRuby.new('# Markdown Title', from: :markdown, to: :rst)
puts @converter.convert

This takes the Markdown formatted string and converts it to reStructuredText.

You can also use the #convert class method:

puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)

Other arguments are simply converted into command line options, accepting symbols and strings for options and hashes for options with arguments.

PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, '--wrap=none', :table_of_contents)

is equivalent to

echo "# Markdown Title" | pandoc -s -f markdown --to=rst --wrap=none --table-of-contents

Also provided are #to_[writer] instance methods for each of the writers, and these can also accept options:

PandocRuby.new('# Example').to_html(:ascii)
# => "<h1 id="example">Example</h1>"
# or
PandocRuby.new("# Example").to_rst
# => "Example
#     ======="

Similarly, there are class methods for each of the readers, so readers and writers can be specified like this:

PandocRuby.html("<h1>hello</h1>").to_latex
# => "\\section{hello}"

Available readers and writers are can be found in the following variables:

PandocRuby assumes the pandoc executable is in your environment's $PATH variable. If you'd like to set an explicit path to the pandoc executable, you can do so with PandocRuby.pandoc_path = '/path/to/pandoc'

Converting Files

PandocRuby can also take an array of one or more file paths as the first argument. The files will be concatenated together with a blank line between each and used as input.

# One file path as a single-element array.
PandocRuby.new(['/path/to/file1.docx'], from: 'docx').to_html
# Multiple file paths as an array.
PandocRuby.new(['/path/to/file1.docx', '/path/to/file1.docx'], from: 'docx').to_html

If you are trying to generate a standalone file with full file headers rather than just a marked up fragment, remember to pass the :standalone option so the correct header and footer are added.

PandocRuby.new("# Some title", :standalone).to_rtf

Extensions

Pandoc extensions can be used to modify the behavior of readers and writers. To use an extension, add the extension with a + or - after the reader or writer name:

# Without extension:
PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict').to_html
# => "<p>Line 1</p>\n<h1>Heading</h1>\n"

# With `+blank_before_header` extension:
PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
# => "<p>Line 1 # Heading</p>\n

More Information

For more information on Pandoc, see the Pandoc documentation or run man pandoc (also available here).

If you'd prefer a pure-Ruby extended markdown interpreter that can output a few different formats, take a look at kramdown. If you want to use the full reStructuredText syntax from within Ruby, check out RbST, a docutils wrapper.

This gem was inspired by Albino. For a slightly different approach to using Pandoc with Ruby, see Pandoku.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

More Repositories

1

nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
Shell
6,205
star
2

bash-boilerplate

A collection of Bash scripts for creating safe and useful command line programs.
Shell
699
star
3

hosts

A command line hosts file editor in one portable script.
Shell
156
star
4

airport

A command line / terminal tool for Wi-Fi on macOS / OS X.
Shell
62
star
5

iso-639

Ruby gem with ISO 639-1 and ISO 639-2 language code entries and convenience methods.
Ruby
60
star
6

bindle

A configuration and dotfile management tool for your personal unix-like computer.
Shell
53
star
7

notes-app-cli

A command line interface for Notes.app on macOS.
Shell
51
star
8

bask

A runner and framework for command-centric Bash scripts.
Shell
39
star
9

vbox

A streamlined interface for VBoxManage, the VirtualBox command line tool.
Shell
36
star
10

dotvim

A full-featured configuration for Vim, Neovim, and MacVim.
Vim Script
30
star
11

osx-cli

A collection of command line shortcuts for common OS X operations.
Shell
24
star
12

pb

A tiny wrapper combining pbcopy & pbpaste in a single command.
Shell
24
star
13

dotfiles

A user environment for Unix-like systems.
Shell
21
star
14

search.sh

A command line search multi-tool.
Shell
21
star
15

redmine_restructuredtext_formatter

reStructuredText formatting for Redmine
Ruby
19
star
16

rbst

A Ruby gem for processing reStructuredText via Python's Docutils
Ruby
18
star
17

astral

A Zsh theme with contextual information and Zen mode.
Shell
14
star
18

user

Command line interface for common macOS user account operations.
Shell
10
star
19

bibliography

TeX
10
star
20

dotfile-research

A collection of items and submodules related to dotfiles.
Shell
8
star
21

spotlight-actions

Use Spotlight on macOS for fast user switching, locking the screen, putting the system to sleep, and other actions.
Shell
6
star
22

starters

A collection of starting points, skeletons, and boilerplate code.
Roff
6
star
23

orphans

Shell
5
star
24

thepub

Extraction of Repub's epub module and related tests
Ruby
5
star
25

landing-page

A very simple Sinatra application as described by Joel Gascoigne for creating a landing page hosted using Heroku and MongoHQ free plans
JavaScript
4
star
26

glyph_imager

Ruby
4
star
27

descendant_nav_tabs

Easy, customizable Rails navigation tabs. Active tab highlighting with a descendant CSS selector.
Ruby
4
star
28

makefile-for-tasks-boilerplate

Shell
3
star
29

dsgn

A simple workflow for design projects.
Shell
3
star
30

an_acl

Rails ACL
Ruby
3
star
31

dict

A command line tool written in Swift for querying definitions from OS X's dictionary.
Swift
3
star
32

parent_resources

DRYing Up Polymorphic Controllers
Ruby
3
star
33

lcclasses

Ruby gem for listing and manipulating Library of Congress Classification classes and subclasses
Ruby
3
star
34

homebrew-taps

My Homebrew formulae.
Ruby
3
star
35

git-mkrepo

Initialize a git repository.
Shell
3
star
36

picky_color

JS color picker based on Prototype/Scriptaculous
JavaScript
2
star
37

git-nest

Improved git subtrees (hopefully).
Shell
2
star
38

kindler

Ruby Kindle library
Ruby
2
star
39

shell-app

Turn a shell script into an OS X application.
Ruby
2
star
40

user_stats

A Sinatra-based middleware plugin template for displaying a user metrics dashboard in Rails applications
Ruby
2
star
41

swiftly

Transparent compilation for Swift command line scripts / programs.
Shell
1
star
42

autocap

My Capistrano Junk Drawer
Ruby
1
star
43

dev-box-examples

A collection of development boxes based on Vagrant and Docker.
1
star
44

jwysiwyg

Fork of jWYSIWYG javascript text editor
1
star
45

sanitize_css

Sanitize CSS using a whitelist
Ruby
1
star
46

alias-app

Create an OS X "alias" application that simply opens another OS X application.
Ruby
1
star