GithubHelp home page GithubHelp logo

unkindpartition / pandoc-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xwmx/pandoc-ruby

1.0 0.0 0.0 153 KB

Lightweight Ruby wrapper for Pandoc

License: MIT License

Ruby 97.09% TeX 1.76% HTML 0.67% Roff 0.49%

pandoc-ruby's Introduction

PandocRuby

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

Pandoc can convert documents in markdown, reStructuredText, textile, HTML, DocBook, LaTeX, or MediaWiki markup to a variety of 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, and Microsoft Word docx.

This documentation is for version 2 and higher. For version 1 documentation see here.

Installation

First, make sure to install Pandoc.

Next, add PandocRuby to your Gemfile

gem 'pandoc-ruby'

or install PandocRuby from RubyGems.

gem install pandoc-ruby

Usage

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

This takes the Markdown formatted file 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 or strings for options without arguments and hashes of strings or symbols for options with arguments.

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

is equivalent to

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

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

PandocRuby.new("# Some title").to_html(:no_wrap)
# => "<div id=\"some-title\"><h1>Some title</h1></div>"
# or
PandocRuby.new("# Some title").to_rst
# => "Some title\n=========="

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}"

PandocRuby assumes the pandoc executable is via 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'

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.html(['/path/to/file1.html']).to_markdown
# Multiple file paths as an array.
PandocRuby.html(['/path/to/file1.html', '/path/to/file2.html']).to_markdown

Available format readers and writers are available in the PandocRuby::READERS and PandocRuby::WRITERS constants.

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 Maruku. 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.

Additional Notes

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

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.

pandoc-ruby's People

Contributors

xwmx avatar changecase avatar dalehamel avatar dsanson avatar wiegand avatar candlerb avatar dginev avatar dkharrat avatar

Stargazers

Lewis Brown avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.