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.
{ '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
-
.pandoc_path ⇒ Object
Returns the value of attribute pandoc_path.
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`.
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)
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. = args end |
Class Attribute Details
.pandoc_path ⇒ Object
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_output ⇒ Object
143 144 145 |
# File 'lib/pandoc-ruby.rb', line 143 def binary_output @binary_output ||= false end |
#input_files ⇒ Object
Returns the value of attribute input_files.
165 166 167 |
# File 'lib/pandoc-ruby.rb', line 165 def input_files @input_files end |
#input_string ⇒ Object
Returns the value of attribute input_string.
166 167 168 |
# File 'lib/pandoc-ruby.rb', line 166 def input_string @input_string end |
#option_string ⇒ Object
155 156 157 |
# File 'lib/pandoc-ruby.rb', line 155 def option_string @option_string ||= '' end |
#options ⇒ Object
149 150 151 |
# File 'lib/pandoc-ruby.rb', line 149 def @options ||= [] end |
#writer ⇒ Object
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. += args if args self.option_string = (self.) if self.binary_output convert_binary else convert_string end end |