pandoc-ruby 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -21
- data/lib/pandoc-ruby.rb +88 -32
- data/pandoc-ruby.gemspec +1 -1
- data/test/test_pandoc_ruby.rb +144 -42
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 560fc0d0f2fe55196b4f1d981d66748af59d29f7b86afa4797fd25109d7ad04c
|
4
|
+
data.tar.gz: 991843c076e7816e99ba11778190e4a0e2b0385f9659a0e5579ecbc5b743d4e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ef270181fe562d955430d0e7fd8198d3a6ddffb4737c2b725f30a7333cd6d49ec36b1e16e72ce7c11273445506b9a861a0cbd42c2a0be15e6ac6d11e2086e04
|
7
|
+
data.tar.gz: a70b8400f8d38bebce010bab5dc8be1ac6b4559b1ad332b237fb2befea15d9080e4850d5a1aab68160513a269000be9c4f3549862b726b092e3fff5047666dfd
|
data/README.md
CHANGED
@@ -10,9 +10,6 @@ markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML,
|
|
10
10
|
OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages,
|
11
11
|
HTML slide shows, EPUB, and Microsoft Word docx.
|
12
12
|
|
13
|
-
*This documentation is for version 2 and higher. For version 1 documentation
|
14
|
-
[see here](https://github.com/xwmx/pandoc-ruby/blob/v1.0.0/README.markdown).*
|
15
|
-
|
16
13
|
## Installation
|
17
14
|
|
18
15
|
First, make sure to
|
@@ -34,7 +31,7 @@ gem install pandoc-ruby
|
|
34
31
|
|
35
32
|
```ruby
|
36
33
|
require 'pandoc-ruby'
|
37
|
-
@converter = PandocRuby.new('# Markdown Title', :
|
34
|
+
@converter = PandocRuby.new('# Markdown Title', from: :markdown, to: :rst)
|
38
35
|
puts @converter.convert
|
39
36
|
```
|
40
37
|
|
@@ -43,7 +40,7 @@ This takes the Markdown formatted file and converts it to reStructuredText.
|
|
43
40
|
You can also use the `#convert` class method:
|
44
41
|
|
45
42
|
```ruby
|
46
|
-
puts PandocRuby.convert('# Markdown Title', :
|
43
|
+
puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)
|
47
44
|
```
|
48
45
|
|
49
46
|
Other arguments are simply converted into command line options, accepting
|
@@ -51,7 +48,7 @@ symbols or strings for options without arguments and hashes of strings or
|
|
51
48
|
symbols for options with arguments.
|
52
49
|
|
53
50
|
```ruby
|
54
|
-
PandocRuby.convert('# Markdown Title', :s, {:
|
51
|
+
PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, 'no-wrap', :table_of_contents)
|
55
52
|
```
|
56
53
|
|
57
54
|
is equivalent to
|
@@ -83,17 +80,45 @@ PandocRuby assumes the `pandoc` executable is via your environment's `$PATH`
|
|
83
80
|
variable. If you'd like to set an explicit path to the `pandoc` executable,
|
84
81
|
you can do so with `PandocRuby.pandoc_path = '/path/to/pandoc'`
|
85
82
|
|
83
|
+
### Converting Files
|
84
|
+
|
86
85
|
PandocRuby can also take an array of one or more file paths as the first
|
87
86
|
argument. The files will be concatenated together with a blank line between
|
88
87
|
each and used as input.
|
89
88
|
|
90
89
|
```ruby
|
91
90
|
# One file path as a single-element array.
|
92
|
-
PandocRuby.
|
91
|
+
PandocRuby.new(['/path/to/file1.docx'], from: 'docx').to_html
|
93
92
|
# Multiple file paths as an array.
|
94
|
-
PandocRuby.
|
93
|
+
PandocRuby.new(['/path/to/file1.docx', '/path/to/file1.docx'], from: 'docx').to_html
|
94
|
+
```
|
95
|
+
|
96
|
+
If you are trying to generate a standalone file with full file headers rather
|
97
|
+
than just a marked up fragment, remember to pass the `:standalone` option so
|
98
|
+
the correct header and footer are added.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
PandocRuby.new("# Some title", :standalone).to_rtf
|
102
|
+
```
|
103
|
+
|
104
|
+
### Extensions
|
105
|
+
|
106
|
+
Pandoc [extensions](https://pandoc.org/MANUAL.html#extensions) can be
|
107
|
+
used to modify the behavior of readers and writers. To use an extension,
|
108
|
+
add the extension with a `+` or `-` after the reader or writer name:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# Without extension
|
112
|
+
PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict').to_html
|
113
|
+
# => "<p>Line 1</p>\n<h1>Heading</h1>\n"
|
114
|
+
|
115
|
+
# With extension:
|
116
|
+
>> PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
|
117
|
+
# => "<p>Line 1 # Heading</p>\n
|
95
118
|
```
|
96
119
|
|
120
|
+
### More Information
|
121
|
+
|
97
122
|
Available format readers and writers are available in the `PandocRuby::READERS`
|
98
123
|
and `PandocRuby::WRITERS` constants.
|
99
124
|
|
@@ -103,24 +128,15 @@ or run `man pandoc`
|
|
103
128
|
([also available here](http://johnmacfarlane.net/pandoc/pandoc.1.html)).
|
104
129
|
|
105
130
|
If you'd prefer a pure-Ruby extended markdown interpreter that can output a
|
106
|
-
few different formats, take a look at
|
107
|
-
If you want to use the full
|
108
|
-
|
131
|
+
few different formats, take a look at
|
132
|
+
[kramdown](https://kramdown.gettalong.org/). If you want to use the full
|
133
|
+
reStructuredText syntax from within Ruby, check out
|
134
|
+
[RbST](https://github.com/xwmx/rbst), a docutils wrapper.
|
109
135
|
|
110
136
|
This gem was inspired by [Albino](http://github.com/github/albino). For a
|
111
137
|
slightly different approach to using Pandoc with Ruby, see
|
112
138
|
[Pandoku](http://github.com/dahlia/pandoku).
|
113
139
|
|
114
|
-
## Additional Notes
|
115
|
-
|
116
|
-
If you are trying to generate a standalone file with full file headers rather
|
117
|
-
than just a marked up fragment, remember to pass the `:standalone` option so
|
118
|
-
the correct header and footer are added.
|
119
|
-
|
120
|
-
```ruby
|
121
|
-
PandocRuby.new("# Some title", :standalone).to_rtf
|
122
|
-
```
|
123
|
-
|
124
140
|
## Note on Patches/Pull Requests
|
125
141
|
|
126
142
|
* Fork the project.
|
data/lib/pandoc-ruby.rb
CHANGED
@@ -8,49 +8,105 @@ class PandocRuby
|
|
8
8
|
# The available readers and their corresponding names. The keys are used to
|
9
9
|
# generate methods and specify options to Pandoc.
|
10
10
|
READERS = {
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
'
|
17
|
-
'
|
11
|
+
'commonmark' => 'CommonMark Markdown',
|
12
|
+
'creole' => 'Creole 1.0',
|
13
|
+
'csv' => 'CSV table',
|
14
|
+
'docbook' => 'DocBook',
|
15
|
+
'docx' => 'Word docx',
|
16
|
+
'dokuwiki' => 'DokuWiki markup',
|
17
|
+
'epub' => 'EPUB',
|
18
|
+
'fb2' => 'FictionBook2 e-book',
|
19
|
+
'gfm' => 'GitHub-Flavored Markdown',
|
20
|
+
'haddock' => 'Haddock markup',
|
21
|
+
'html' => 'HTML',
|
22
|
+
'ipynb' => 'Jupyter notebook',
|
23
|
+
'jats' => 'JATS XML',
|
24
|
+
'jira' => 'Jira wiki markup',
|
25
|
+
'json' => 'JSON version of native AST',
|
26
|
+
'latex' => 'LaTex',
|
27
|
+
'man' => 'roff man',
|
28
|
+
'markdown' => "Pandoc's Markdown",
|
29
|
+
'markdown_mmd' => 'MultiMarkdown',
|
30
|
+
'markdown_phpextra' => 'PHP Markdown Extra',
|
31
|
+
'markdown_strict' => 'original unextended Markdown',
|
32
|
+
'mediawiki' => 'MediaWiki markup',
|
33
|
+
'muse' => 'Muse',
|
34
|
+
'native' => 'native Haskell',
|
35
|
+
'odt' => 'ODT',
|
36
|
+
'opml' => 'OPML',
|
37
|
+
'org' => 'Emacs Org mode',
|
38
|
+
'rst' => 'reStructuredText',
|
39
|
+
't2t' => 'txt2tags',
|
40
|
+
'textile' => 'Textile',
|
41
|
+
'tikiwiki' => 'TikiWiki markup',
|
42
|
+
'twiki' => 'TWiki markup',
|
43
|
+
'vimwiki' => 'Vimwiki'
|
18
44
|
}.freeze
|
19
45
|
|
20
46
|
# The available string writers and their corresponding names. The keys are
|
21
47
|
# used to generate methods and specify options to Pandoc.
|
22
48
|
STRING_WRITERS = {
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
49
|
+
'asciidoc' => 'AsciiDoc',
|
50
|
+
'asciidoctor' => 'AsciiDoctor',
|
51
|
+
'beamer' => 'LaTeX beamer slide show',
|
52
|
+
'commonmark' => 'CommonMark Markdown',
|
53
|
+
'context' => 'ConTeXt',
|
54
|
+
'docbook' => 'DocBook 4',
|
55
|
+
'docbook4' => 'DocBook 4',
|
56
|
+
'docbook5' => 'DocBook 5',
|
57
|
+
'dokuwiki' => 'DokuWiki markup',
|
58
|
+
'fb2' => 'FictionBook2 e-book',
|
59
|
+
'gfm' => 'GitHub-Flavored Markdown',
|
60
|
+
'haddock' => 'Haddock markup',
|
61
|
+
'html' => 'HTML, i.e. HTML5/XHTML polyglot markup',
|
62
|
+
'html5' => 'HTML, i.e. HTML5/XHTML polyglot markup',
|
63
|
+
'html4' => 'XHTML 1.0 Transitional',
|
64
|
+
'icml' => 'InDesign ICML',
|
65
|
+
'ipynb' => 'Jupyter notebook',
|
66
|
+
'jats_archiving' => 'JATS XML, Archiving and Interchange Tag Set',
|
67
|
+
'jats_articleauthoring' => 'JATS XML, Article Authoring Tag Set',
|
68
|
+
'jats_publishing' => 'JATS XML, Journal Publishing Tag Set',
|
69
|
+
'jats' => 'alias for jats_archiving',
|
70
|
+
'jira' => 'Jira wiki markup',
|
71
|
+
'json' => 'JSON version of native AST',
|
72
|
+
'latex' => 'LaTex',
|
73
|
+
'man' => 'roff man',
|
74
|
+
'markdown' => "Pandoc's Markdown",
|
75
|
+
'markdown_mmd' => 'MultiMarkdown',
|
76
|
+
'markdown_phpextra' => 'PHP Markdown Extra',
|
77
|
+
'markdown_strict' => 'original unextended Markdown',
|
78
|
+
'mediawiki' => 'MediaWiki markup',
|
79
|
+
'ms' => 'roff ms',
|
80
|
+
'muse' => 'Muse',
|
81
|
+
'native' => 'native Haskell',
|
82
|
+
'opml' => 'OPML',
|
83
|
+
'opendocument' => 'OpenDocument',
|
84
|
+
'org' => 'Emacs Org mode',
|
85
|
+
'pdf' => 'PDF',
|
86
|
+
'plain' => 'plain text',
|
87
|
+
'pptx' => 'PowerPoint slide show',
|
88
|
+
'rst' => 'reStructuredText',
|
89
|
+
'rtf' => 'Rich Text Format',
|
90
|
+
'texinfo' => 'GNU Texinfo',
|
91
|
+
'textile' => 'Textile',
|
92
|
+
'slideous' => 'Slideous HTML and JavaScript slide show',
|
93
|
+
'slidy' => 'Slidy HTML and JavaScript slide show',
|
94
|
+
'dzslides' => 'DZSlides HTML5 + JavaScript slide show',
|
95
|
+
'revealjs' => 'reveal.js HTML5 + JavaScript slide show',
|
96
|
+
's5' => 'S5 HTML and JavaScript slide show',
|
97
|
+
'tei' => 'TEI Simple',
|
98
|
+
'xwiki' => 'XWiki markup',
|
99
|
+
'zimwiki' => 'ZimWiki markup'
|
45
100
|
}.freeze
|
46
101
|
|
47
102
|
# The available binary writers and their corresponding names. The keys are
|
48
103
|
# used to generate methods and specify options to Pandoc.
|
49
104
|
BINARY_WRITERS = {
|
50
|
-
'odt' => '
|
105
|
+
'odt' => 'OpenOffice text document',
|
51
106
|
'docx' => 'Word docx',
|
52
|
-
'epub' => 'EPUB
|
53
|
-
'
|
107
|
+
'epub' => 'EPUB v2',
|
108
|
+
'epub2' => 'EPUB v2',
|
109
|
+
'epub3' => 'EPUB v3'
|
54
110
|
}.freeze
|
55
111
|
|
56
112
|
# All of the available Writers.
|
data/pandoc-ruby.gemspec
CHANGED
data/test/test_pandoc_ruby.rb
CHANGED
@@ -75,7 +75,7 @@ describe PandocRuby do
|
|
75
75
|
assert converter.convert(:s, { :f => :markdown, :to => :rst }, 'no-wrap')
|
76
76
|
end
|
77
77
|
|
78
|
-
it 'converts underscore symbol
|
78
|
+
it 'converts underscore symbol args to hyphenated long options' do
|
79
79
|
converter = PandocRuby.new(@string, {
|
80
80
|
:email_obfuscation => :javascript
|
81
81
|
}, :table_of_contents)
|
@@ -92,6 +92,44 @@ describe PandocRuby do
|
|
92
92
|
assert converter.convert
|
93
93
|
end
|
94
94
|
|
95
|
+
it 'supports reader extensions' do
|
96
|
+
assert_equal(
|
97
|
+
PandocRuby.convert(
|
98
|
+
"Line 1\n# Heading",
|
99
|
+
:from => 'markdown_strict',
|
100
|
+
:to => 'html'
|
101
|
+
),
|
102
|
+
"<p>Line 1</p>\n<h1>Heading</h1>\n"
|
103
|
+
)
|
104
|
+
assert_equal(
|
105
|
+
PandocRuby.convert(
|
106
|
+
"Line 1\n# Heading",
|
107
|
+
:from => 'markdown_strict+blank_before_header',
|
108
|
+
:to => 'html'
|
109
|
+
),
|
110
|
+
"<p>Line 1 # Heading</p>\n"
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'supports writer extensions' do
|
115
|
+
assert_equal(
|
116
|
+
PandocRuby.convert(
|
117
|
+
"<sub>example</sub>\n",
|
118
|
+
:from => 'html',
|
119
|
+
:to => 'markdown'
|
120
|
+
),
|
121
|
+
"~example~\n"
|
122
|
+
)
|
123
|
+
assert_equal(
|
124
|
+
PandocRuby.convert(
|
125
|
+
"<sub>example</sub>\n",
|
126
|
+
:from => 'html',
|
127
|
+
:to => 'markdown-subscript'
|
128
|
+
),
|
129
|
+
"<sub>example</sub>\n"
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
95
133
|
it 'raises RuntimeError from pandoc executable error' do
|
96
134
|
assert_raises(RuntimeError) do
|
97
135
|
PandocRuby.new('# hello', 'badopt').to_html5
|
@@ -177,46 +215,110 @@ Pandoc no longer times out with test file. Determine how to test.
|
|
177
215
|
end
|
178
216
|
|
179
217
|
it 'has reader and writer constants' do
|
180
|
-
assert_equal
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
218
|
+
assert_equal(
|
219
|
+
PandocRuby::READERS,
|
220
|
+
'commonmark' => 'CommonMark Markdown',
|
221
|
+
'creole' => 'Creole 1.0',
|
222
|
+
'csv' => 'CSV table',
|
223
|
+
'docbook' => 'DocBook',
|
224
|
+
'docx' => 'Word docx',
|
225
|
+
'dokuwiki' => 'DokuWiki markup',
|
226
|
+
'epub' => 'EPUB',
|
227
|
+
'fb2' => 'FictionBook2 e-book',
|
228
|
+
'gfm' => 'GitHub-Flavored Markdown',
|
229
|
+
'haddock' => 'Haddock markup',
|
230
|
+
'html' => 'HTML',
|
231
|
+
'ipynb' => 'Jupyter notebook',
|
232
|
+
'jats' => 'JATS XML',
|
233
|
+
'jira' => 'Jira wiki markup',
|
234
|
+
'json' => 'JSON version of native AST',
|
235
|
+
'latex' => 'LaTex',
|
236
|
+
'man' => 'roff man',
|
237
|
+
'markdown' => "Pandoc's Markdown",
|
238
|
+
'markdown_mmd' => 'MultiMarkdown',
|
239
|
+
'markdown_phpextra' => 'PHP Markdown Extra',
|
240
|
+
'markdown_strict' => 'original unextended Markdown',
|
241
|
+
'mediawiki' => 'MediaWiki markup',
|
242
|
+
'muse' => 'Muse',
|
243
|
+
'native' => 'native Haskell',
|
244
|
+
'odt' => 'ODT',
|
245
|
+
'opml' => 'OPML',
|
246
|
+
'org' => 'Emacs Org mode',
|
247
|
+
'rst' => 'reStructuredText',
|
248
|
+
't2t' => 'txt2tags',
|
249
|
+
'textile' => 'Textile',
|
250
|
+
'tikiwiki' => 'TikiWiki markup',
|
251
|
+
'twiki' => 'TWiki markup',
|
252
|
+
'vimwiki' => 'Vimwiki'
|
253
|
+
)
|
254
|
+
|
255
|
+
assert_equal(
|
256
|
+
PandocRuby::STRING_WRITERS,
|
257
|
+
'asciidoc' => 'AsciiDoc',
|
258
|
+
'asciidoctor' => 'AsciiDoctor',
|
259
|
+
'beamer' => 'LaTeX beamer slide show',
|
260
|
+
'commonmark' => 'CommonMark Markdown',
|
261
|
+
'context' => 'ConTeXt',
|
262
|
+
'docbook' => 'DocBook 4',
|
263
|
+
'docbook4' => 'DocBook 4',
|
264
|
+
'docbook5' => 'DocBook 5',
|
265
|
+
'dokuwiki' => 'DokuWiki markup',
|
266
|
+
'fb2' => 'FictionBook2 e-book',
|
267
|
+
'gfm' => 'GitHub-Flavored Markdown',
|
268
|
+
'haddock' => 'Haddock markup',
|
269
|
+
'html' => 'HTML, i.e. HTML5/XHTML polyglot markup',
|
270
|
+
'html5' => 'HTML, i.e. HTML5/XHTML polyglot markup',
|
271
|
+
'html4' => 'XHTML 1.0 Transitional',
|
272
|
+
'icml' => 'InDesign ICML',
|
273
|
+
'ipynb' => 'Jupyter notebook',
|
274
|
+
'jats_archiving' => 'JATS XML, Archiving and Interchange Tag Set',
|
275
|
+
'jats_articleauthoring' => 'JATS XML, Article Authoring Tag Set',
|
276
|
+
'jats_publishing' => 'JATS XML, Journal Publishing Tag Set',
|
277
|
+
'jats' => 'alias for jats_archiving',
|
278
|
+
'jira' => 'Jira wiki markup',
|
279
|
+
'json' => 'JSON version of native AST',
|
280
|
+
'latex' => 'LaTex',
|
281
|
+
'man' => 'roff man',
|
282
|
+
'markdown' => "Pandoc's Markdown",
|
283
|
+
'markdown_mmd' => 'MultiMarkdown',
|
284
|
+
'markdown_phpextra' => 'PHP Markdown Extra',
|
285
|
+
'markdown_strict' => 'original unextended Markdown',
|
286
|
+
'mediawiki' => 'MediaWiki markup',
|
287
|
+
'ms' => 'roff ms',
|
288
|
+
'muse' => 'Muse',
|
289
|
+
'native' => 'native Haskell',
|
290
|
+
'opml' => 'OPML',
|
291
|
+
'opendocument' => 'OpenDocument',
|
292
|
+
'org' => 'Emacs Org mode',
|
293
|
+
'pdf' => 'PDF',
|
294
|
+
'plain' => 'plain text',
|
295
|
+
'pptx' => 'PowerPoint slide show',
|
296
|
+
'rst' => 'reStructuredText',
|
297
|
+
'rtf' => 'Rich Text Format',
|
298
|
+
'texinfo' => 'GNU Texinfo',
|
299
|
+
'textile' => 'Textile',
|
300
|
+
'slideous' => 'Slideous HTML and JavaScript slide show',
|
301
|
+
'slidy' => 'Slidy HTML and JavaScript slide show',
|
302
|
+
'dzslides' => 'DZSlides HTML5 + JavaScript slide show',
|
303
|
+
'revealjs' => 'reveal.js HTML5 + JavaScript slide show',
|
304
|
+
's5' => 'S5 HTML and JavaScript slide show',
|
305
|
+
'tei' => 'TEI Simple',
|
306
|
+
'xwiki' => 'XWiki markup',
|
307
|
+
'zimwiki' => 'ZimWiki markup'
|
308
|
+
)
|
309
|
+
|
310
|
+
assert_equal(
|
311
|
+
PandocRuby::BINARY_WRITERS,
|
312
|
+
'odt' => 'OpenOffice text document',
|
313
|
+
'docx' => 'Word docx',
|
314
|
+
'epub' => 'EPUB v2',
|
315
|
+
'epub2' => 'EPUB v2',
|
316
|
+
'epub3' => 'EPUB v3'
|
317
|
+
)
|
318
|
+
|
319
|
+
assert_equal(
|
320
|
+
PandocRuby::WRITERS,
|
321
|
+
PandocRuby::STRING_WRITERS.merge(PandocRuby::BINARY_WRITERS)
|
322
|
+
)
|
221
323
|
end
|
222
324
|
end
|