Class: PandocRuby
- Inherits:
-
Object
- Object
- PandocRuby
- 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.
{ 'commonmark' => 'CommonMark Markdown', 'creole' => 'Creole 1.0', 'csv' => 'CSV table', 'docbook' => 'DocBook', 'docx' => 'Word docx', 'dokuwiki' => 'DokuWiki markup', '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', 'rst' => 'reStructuredText', 't2t' => 'txt2tags', 'textile' => 'Textile', 'tikiwiki' => 'TikiWiki markup', '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', 'commonmark' => 'CommonMark Markdown', 'context' => 'ConTeXt', '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', '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 v2', 'epub2' => 'EPUB v2', 'epub3' => 'EPUB v3' }.freeze
- WRITERS =
All of the available Writers.
STRING_WRITERS.merge(BINARY_WRITERS)
- @@pandoc_path =
'pandoc'
Instance Attribute Summary collapse
- #binary_output ⇒ Object
-
#input_files ⇒ Object
Returns the value of attribute input_files.
-
#input_string ⇒ Object
Returns the value of attribute input_string.
- #option_string ⇒ Object
- #options ⇒ Object
- #writer ⇒ Object
Class Method Summary collapse
-
.convert(*args) ⇒ Object
A shortcut method that creates a new PandocRuby object and immediately calls ‘#convert`.
-
.pandoc_path=(path) ⇒ Object
To use run the pandoc command with a custom executable path, the path to the pandoc executable can be set here.
Instance Method Summary collapse
-
#convert(*args) ⇒ Object
(also: #to_s)
Run the conversion.
-
#initialize(*args) ⇒ PandocRuby
constructor
Create a new PandocRuby converter object.
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)
161 162 163 164 165 166 167 168 |
# File 'lib/pandoc-ruby.rb', line 161 def initialize(*args) if args[0].is_a?(String) self.input_string = args.shift elsif args[0].is_a?(Array) self.input_files = args.shift.join(' ') end self. = args end |
Instance Attribute Details
#binary_output ⇒ Object
130 131 132 |
# File 'lib/pandoc-ruby.rb', line 130 def binary_output @binary_output ||= false end |
#input_files ⇒ Object
Returns the value of attribute input_files.
149 150 151 |
# File 'lib/pandoc-ruby.rb', line 149 def input_files @input_files end |
#input_string ⇒ Object
Returns the value of attribute input_string.
150 151 152 |
# File 'lib/pandoc-ruby.rb', line 150 def input_string @input_string end |
#option_string ⇒ Object
140 141 142 |
# File 'lib/pandoc-ruby.rb', line 140 def option_string @option_string ||= '' end |
#options ⇒ Object
135 136 137 |
# File 'lib/pandoc-ruby.rb', line 135 def @options ||= [] end |
#writer ⇒ Object
145 146 147 |
# File 'lib/pandoc-ruby.rb', line 145 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.
125 126 127 |
# File 'lib/pandoc-ruby.rb', line 125 def self.convert(*args) new(*args).convert end |
.pandoc_path=(path) ⇒ Object
To use run the pandoc command with a custom executable path, the path to the pandoc executable can be set here.
117 118 119 |
# File 'lib/pandoc-ruby.rb', line 117 def self.pandoc_path=(path) @@pandoc_path = path 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"
181 182 183 184 185 186 187 188 189 |
# File 'lib/pandoc-ruby.rb', line 181 def convert(*args) self. += args if args self.option_string = (self.) if self.binary_output convert_binary else convert_string end end |