Class: PandocRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/pandoc-ruby.rb

Constant Summary collapse

READERS =

The available readers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.

{
  'biblatex'          => 'BibLaTeX bibliography',
  'bibtex'            => 'BibTeX bibliography',
  'commonmark'        => 'CommonMark Markdown',
  'commonmark_x'      => 'CommonMark Markdown with extensions',
  'creole'            => 'Creole 1.0',
  'csljson'           => 'CSL JSON bibliography',
  'csv'               => 'CSV table',
  'docbook'           => 'DocBook',
  'docx'              => 'Word docx',
  'dokuwiki'          => 'DokuWiki markup',
  'endnotexml'        => 'EndNote XML bibliography',
  'epub'              => 'EPUB',
  'fb2'               => 'FictionBook2 e-book',
  'gfm'               => 'GitHub-Flavored Markdown',
  'haddock'           => 'Haddock markup',
  'html'              => 'HTML',
  'ipynb'             => 'Jupyter notebook',
  'jats'              => 'JATS XML',
  'jira'              => 'Jira wiki markup',
  'json'              => 'JSON version of native AST',
  'latex'             => 'LaTex',
  'man'               => 'roff man',
  'markdown'          => "Pandoc's Markdown",
  'markdown_mmd'      => 'MultiMarkdown',
  'markdown_phpextra' => 'PHP Markdown Extra',
  'markdown_strict'   => 'original unextended Markdown',
  'mediawiki'         => 'MediaWiki markup',
  'muse'              => 'Muse',
  'native'            => 'native Haskell',
  'odt'               => 'ODT',
  'opml'              => 'OPML',
  'org'               => 'Emacs Org mode',
  'ris'               => 'RIS bibliography',
  'rst'               => 'reStructuredText',
  'rtf'               => 'Rich Text Format',
  't2t'               => 'txt2tags',
  'textile'           => 'Textile',
  'tikiwiki'          => 'TikiWiki markup',
  'tsv'               => 'TSV table',
  'twiki'             => 'TWiki markup',
  'vimwiki'           => 'Vimwiki'
}.freeze
STRING_WRITERS =

The available string writers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.

{
  'asciidoc'              => 'AsciiDoc',
  'asciidoctor'           => 'AsciiDoctor',
  'beamer'                => 'LaTeX beamer slide show',
  'biblatex'              => 'BibLaTeX bibliography',
  'bibtex'                => 'BibTeX bibliography',
  'chunkedhtml'           => 'zip archive of multiple linked HTML files',
  'commonmark'            => 'CommonMark Markdown',
  'commonmark_x'          => 'CommonMark Markdown with extensions',
  'context'               => 'ConTeXt',
  'csljson'               => 'CSL JSON bibliography',
  'docbook'               => 'DocBook 4',
  'docbook4'              => 'DocBook 4',
  'docbook5'              => 'DocBook 5',
  'dokuwiki'              => 'DokuWiki markup',
  'fb2'                   => 'FictionBook2 e-book',
  'gfm'                   => 'GitHub-Flavored Markdown',
  'haddock'               => 'Haddock markup',
  'html'                  => 'HTML, i.e.  HTML5/XHTML polyglot markup',
  'html5'                 => 'HTML, i.e.  HTML5/XHTML polyglot markup',
  'html4'                 => 'XHTML 1.0 Transitional',
  'icml'                  => 'InDesign ICML',
  'ipynb'                 => 'Jupyter notebook',
  'jats_archiving'        => 'JATS XML, Archiving and Interchange Tag Set',
  'jats_articleauthoring' => 'JATS XML, Article Authoring Tag Set',
  'jats_publishing'       => 'JATS XML, Journal Publishing Tag Set',
  'jats'                  => 'alias for jats_archiving',
  'jira'                  => 'Jira wiki markup',
  'json'                  => 'JSON version of native AST',
  'latex'                 => 'LaTex',
  'man'                   => 'roff man',
  'markdown'              => "Pandoc's Markdown",
  'markdown_mmd'          => 'MultiMarkdown',
  'markdown_phpextra'     => 'PHP Markdown Extra',
  'markdown_strict'       => 'original unextended Markdown',
  'markua'                => 'Markua',
  'mediawiki'             => 'MediaWiki markup',
  'ms'                    => 'roff ms',
  'muse'                  => 'Muse',
  'native'                => 'native Haskell',
  'opml'                  => 'OPML',
  'opendocument'          => 'OpenDocument',
  'org'                   => 'Emacs Org mode',
  'pdf'                   => 'PDF',
  'plain'                 => 'plain text',
  'pptx'                  => 'PowerPoint slide show',
  'rst'                   => 'reStructuredText',
  'rtf'                   => 'Rich Text Format',
  'texinfo'               => 'GNU Texinfo',
  'textile'               => 'Textile',
  'slideous'              => 'Slideous HTML and JavaScript slide show',
  'slidy'                 => 'Slidy HTML and JavaScript slide show',
  'dzslides'              => 'DZSlides HTML5 + JavaScript slide show',
  'revealjs'              => 'reveal.js HTML5 + JavaScript slide show',
  's5'                    => 'S5 HTML and JavaScript slide show',
  'tei'                   => 'TEI Simple',
  'xwiki'                 => 'XWiki markup',
  'zimwiki'               => 'ZimWiki markup'
}.freeze
BINARY_WRITERS =

The available binary writers and their corresponding names. The keys are used to generate methods and specify options to Pandoc.

{
  'odt'   => 'OpenOffice text document',
  'docx'  => 'Word docx',
  'epub'  => 'EPUB v3',
  'epub2' => 'EPUB v2',
  'epub3' => 'EPUB v3'
}.freeze
WRITERS =

All of the available Writers.

STRING_WRITERS.merge(BINARY_WRITERS)

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PandocRuby

Create a new PandocRuby converter object. The first argument contains the input either as string or as an array of filenames.

Any other arguments will be converted to pandoc options.

Usage:

new("# A String", :option1 => :value, :option2)
new(["/path/to/file.md"], :option1 => :value, :option2)
new(["/to/file1.html", "/to/file2.html"], :option1 => :value)


177
178
179
180
181
182
183
184
185
186
# File 'lib/pandoc-ruby.rb', line 177

def initialize(*args)
  case args[0]
  when String
    self.input_string = args.shift
  when Array
    self.input_files  = args.shift.map { |f| "'#{f}'" }.join(' ')
  end

  self.options = args
end

Class Attribute Details

.pandoc_pathObject

Returns the value of attribute pandoc_path.



9
10
11
# File 'lib/pandoc-ruby.rb', line 9

def pandoc_path
  @pandoc_path
end

Instance Attribute Details

#binary_outputObject



143
144
145
# File 'lib/pandoc-ruby.rb', line 143

def binary_output
  @binary_output  ||= false
end

#input_filesObject

Returns the value of attribute input_files.



165
166
167
# File 'lib/pandoc-ruby.rb', line 165

def input_files
  @input_files
end

#input_stringObject

Returns the value of attribute input_string.



166
167
168
# File 'lib/pandoc-ruby.rb', line 166

def input_string
  @input_string
end

#option_stringObject



155
156
157
# File 'lib/pandoc-ruby.rb', line 155

def option_string
  @option_string  ||= ''
end

#optionsObject



149
150
151
# File 'lib/pandoc-ruby.rb', line 149

def options
  @options        ||= []
end

#writerObject



161
162
163
# File 'lib/pandoc-ruby.rb', line 161

def writer
  @writer         ||= 'html'
end

Class Method Details

.convert(*args) ⇒ Object

A shortcut method that creates a new PandocRuby object and immediately calls ‘#convert`. Options passed to this method are passed directly to `#new` and treated the same as if they were passed directly to the initializer.



137
138
139
# File 'lib/pandoc-ruby.rb', line 137

def self.convert(*args)
  new(*args).convert
end

Instance Method Details

#convert(*args) ⇒ Object Also known as: to_s

Run the conversion. The convert method can take any number of arguments, which will be converted to pandoc options. If options were already specified in an initializer or reader method, they will be combined with any that are passed to this method.

Returns a string with the converted content.

Example:

PandocRuby.new("# text").convert
# => "<h1 id=\"text\">text</h1>\n"


199
200
201
202
203
204
205
206
207
208
# File 'lib/pandoc-ruby.rb', line 199

def convert(*args)
  self.options        +=  args if args
  self.option_string  =   prepare_options(self.options)

  if self.binary_output
    convert_binary
  else
    convert_string
  end
end