All Projects → xwmx → Pandoc Ruby

xwmx / Pandoc Ruby

Licence: mit
Ruby wrapper for Pandoc

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Pandoc Ruby

Django Markupfield
📑 a MarkupField for Django
Stars: ✭ 184 (-38.46%)
Mutual labels:  markdown, markup, restructuredtext
Badges
📝 Markdown code for lots of small badges 🎀 📌 (shields.io, forthebadge.com etc) 😎. Contributions are welcome! Please add yours!
Stars: ✭ 2,987 (+899%)
Mutual labels:  markdown, markup, restructuredtext
Markup.rocks
Pandoc based document editor and converter in your browser.
Stars: ✭ 348 (+16.39%)
Mutual labels:  markdown, pandoc, markup
Awesome Scientific Writing
⌨️ A curated list of awesome tools, demos and resources to go beyond LaTeX
Stars: ✭ 162 (-45.82%)
Mutual labels:  markdown, pandoc, restructuredtext
Pandoc
Universal markup converter
Stars: ✭ 24,250 (+8010.37%)
Mutual labels:  markdown, pandoc, markup
Pandoc Markdown Template
Markdown templates for Pandoc
Stars: ✭ 135 (-54.85%)
Mutual labels:  markdown, pandoc
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (-44.15%)
Mutual labels:  markdown, markup
Rmarkdown
Dynamic Documents for R
Stars: ✭ 2,319 (+675.59%)
Mutual labels:  markdown, pandoc
Pandoc Markdown Book Template
A template for creating epub books from markdown using pandoc.
Stars: ✭ 191 (-36.12%)
Mutual labels:  markdown, pandoc
Scroll
Static publishing software with a newspaper feel built on Tree Notation. Scroll is public domain software.
Stars: ✭ 206 (-31.1%)
Mutual labels:  markdown, markup
Panflute
An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions
Stars: ✭ 286 (-4.35%)
Mutual labels:  markdown, pandoc
Pandoc Action Example
using the pandoc document converter on GitHub Actions
Stars: ✭ 131 (-56.19%)
Mutual labels:  markdown, pandoc
M2r
Markdown to reStructuredText converter
Stars: ✭ 232 (-22.41%)
Mutual labels:  markdown, restructuredtext
Patat
Terminal-based presentations using Pandoc
Stars: ✭ 1,725 (+476.92%)
Mutual labels:  markdown, pandoc
Tufte Pandoc Css
Starter files for using Pandoc Markdown with Tufte CSS
Stars: ✭ 215 (-28.09%)
Mutual labels:  markdown, pandoc
Emacs Easy Hugo
Emacs major mode for managing hugo
Stars: ✭ 235 (-21.4%)
Mutual labels:  markdown, restructuredtext
Pandiff
Prose diffs for any document format supported by Pandoc
Stars: ✭ 110 (-63.21%)
Mutual labels:  markdown, pandoc
Pander
An R Pandoc Writer: Convert arbitrary R objects into markdown
Stars: ✭ 267 (-10.7%)
Mutual labels:  markdown, pandoc
Retext
ReText: Simple but powerful editor for Markdown and reStructuredText
Stars: ✭ 1,500 (+401.67%)
Mutual labels:  markdown, restructuredtext
Oscp Exam Report Template Markdown
📙 Markdown Templates for Offensive Security OSCP, OSWE, OSCE, OSEE, OSWP exam report
Stars: ✭ 2,066 (+590.97%)
Mutual labels:  markdown, 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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].