pandoc-ruby 2.1.1 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 560fc0d0f2fe55196b4f1d981d66748af59d29f7b86afa4797fd25109d7ad04c
4
- data.tar.gz: 991843c076e7816e99ba11778190e4a0e2b0385f9659a0e5579ecbc5b743d4e0
3
+ metadata.gz: cae685a045d8dbe0031568787e914fc4a3a6ac2228abf9cb5447ee41cebddfe4
4
+ data.tar.gz: e603e4caa7038e4b299457c8ad9e48464d6283ecaa02ac5dc383d27e7f768b2f
5
5
  SHA512:
6
- metadata.gz: 8ef270181fe562d955430d0e7fd8198d3a6ddffb4737c2b725f30a7333cd6d49ec36b1e16e72ce7c11273445506b9a861a0cbd42c2a0be15e6ac6d11e2086e04
7
- data.tar.gz: a70b8400f8d38bebce010bab5dc8be1ac6b4559b1ad332b237fb2befea15d9080e4850d5a1aab68160513a269000be9c4f3549862b726b092e3fff5047666dfd
6
+ metadata.gz: b066e046f9f55034567f483b037481c933b4c754cfe776133c002f15968999f27a924ebb2ce6d726637741e734893439b6f4ec3ae1157647641be274e11273c3
7
+ data.tar.gz: ded6cbe85511048fc67b07aba3b6ed83610bfce88ac391e820c80ad341c3fe886e4109695dab660b6fe58dad6aaeb2460d6b882a324169d582d64c3c9ade7352
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- minitest (5.14.0)
5
- mocha (1.11.2)
6
- rake (13.0.1)
7
- rdoc (6.2.1)
4
+ minitest (5.14.4)
5
+ mocha (1.13.0)
6
+ rake (13.0.6)
7
+ rdoc (6.3.3)
8
8
 
9
9
  PLATFORMS
10
10
  ruby
@@ -16,4 +16,4 @@ DEPENDENCIES
16
16
  rdoc
17
17
 
18
18
  BUNDLED WITH
19
- 2.1.4
19
+ 2.2.28
data/README.md CHANGED
@@ -1,32 +1,38 @@
1
1
  # PandocRuby
2
2
 
3
+ [![Build Status](https://travis-ci.org/xwmx/pandoc-ruby.svg?branch=master)](https://travis-ci.org/xwmx/pandoc-ruby)
4
+ [![Gem Version](https://img.shields.io/gem/v/pandoc-ruby)](http://rubygems.org/gems/pandoc-ruby)
5
+ [![Gem Downloads](https://img.shields.io/gem/dt/pandoc-ruby)](http://rubygems.org/gems/pandoc-ruby)
6
+
3
7
  PandocRuby is a wrapper for [Pandoc](http://johnmacfarlane.net/pandoc/), a
4
8
  Haskell library with command line tools for converting one markup format to
5
9
  another.
6
10
 
7
- Pandoc can convert documents in markdown, reStructuredText, textile, HTML,
8
- DocBook, LaTeX, or MediaWiki markup to a variety of formats, including
9
- markdown, reStructuredText, HTML, LaTeX, ConTeXt, PDF, RTF, DocBook XML,
10
- OpenDocument XML, ODT, GNU Texinfo, MediaWiki markup, groff man pages,
11
- HTML slide shows, EPUB, and Microsoft Word docx.
11
+ Pandoc can convert documents from a variety of formats including markdown,
12
+ reStructuredText, textile, HTML, DocBook, LaTeX, and MediaWiki markup to a
13
+ variety of other formats, including markdown, reStructuredText, HTML, LaTeX,
14
+ ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki
15
+ markup, groff man pages, HTML slide shows, EPUB, Microsoft Word docx, and more.
12
16
 
13
17
  ## Installation
14
18
 
15
- First, make sure to
16
- [install Pandoc](http://johnmacfarlane.net/pandoc/installing.html).
19
+ First, [install Pandoc](http://johnmacfarlane.net/pandoc/installing.html).
17
20
 
18
- Next, add PandocRuby to your Gemfile
21
+ PandocRuby is available on [RubyGems](http://rubygems.org/gems/pandoc-ruby):
19
22
 
20
- ```ruby
21
- gem 'pandoc-ruby'
23
+ ```bash
24
+ gem install pandoc-ruby
22
25
  ```
23
26
 
24
- or install PandocRuby from [RubyGems](http://rubygems.org/gems/pandoc-ruby).
27
+ To install with [Bundler](https://bundler.io/), add the following to your
28
+ Gemfile:
25
29
 
26
- ```bash
27
- gem install pandoc-ruby
30
+ ```ruby
31
+ gem 'pandoc-ruby'
28
32
  ```
29
33
 
34
+ Then run `bundle install`
35
+
30
36
  ## Usage
31
37
 
32
38
  ```ruby
@@ -35,7 +41,7 @@ require 'pandoc-ruby'
35
41
  puts @converter.convert
36
42
  ```
37
43
 
38
- This takes the Markdown formatted file and converts it to reStructuredText.
44
+ This takes the Markdown formatted string and converts it to reStructuredText.
39
45
 
40
46
  You can also use the `#convert` class method:
41
47
 
@@ -44,28 +50,28 @@ puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)
44
50
  ```
45
51
 
46
52
  Other arguments are simply converted into command line options, accepting
47
- symbols or strings for options without arguments and hashes of strings or
48
- symbols for options with arguments.
53
+ symbols and strings for options and hashes for options with arguments.
49
54
 
50
55
  ```ruby
51
- PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, 'no-wrap', :table_of_contents)
56
+ PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, '--wrap=none', :table_of_contents)
52
57
  ```
53
58
 
54
59
  is equivalent to
55
60
 
56
61
  ```bash
57
- echo "# Markdown Title" | pandoc -s -f markdown --to=rst --no-wrap --table-of-contents
62
+ echo "# Markdown Title" | pandoc -s -f markdown --to=rst --wrap=none --table-of-contents
58
63
  ```
59
64
 
60
65
  Also provided are `#to_[writer]` instance methods for each of the writers,
61
66
  and these can also accept options:
62
67
 
63
68
  ```ruby
64
- PandocRuby.new("# Some title").to_html(:no_wrap)
65
- # => "<div id=\"some-title\"><h1>Some title</h1></div>"
69
+ PandocRuby.new('# Example').to_html(:ascii)
70
+ # => "<h1 id="example">Example</h1>"
66
71
  # or
67
- PandocRuby.new("# Some title").to_rst
68
- # => "Some title\n=========="
72
+ PandocRuby.new("# Example").to_rst
73
+ # => "Example
74
+ # ======="
69
75
  ```
70
76
 
71
77
  Similarly, there are class methods for each of the readers, so readers
@@ -76,7 +82,14 @@ PandocRuby.html("<h1>hello</h1>").to_latex
76
82
  # => "\\section{hello}"
77
83
  ```
78
84
 
79
- PandocRuby assumes the `pandoc` executable is via your environment's `$PATH`
85
+ Available readers and writers are can be found in the following
86
+ variables:
87
+ - [`PandocRuby::READERS`](lib/pandoc-ruby.rb#L10)
88
+ - [`PandocRuby::STRING_WRITERS`](lib/pandoc-ruby.rb#L48)
89
+ - [`PandocRuby::BINARY_WRITERS`](lib/pandoc-ruby.rb#L104)
90
+ - [`PandocRuby::WRITERS`](lib/pandoc-ruby.rb#L113)
91
+
92
+ PandocRuby assumes the `pandoc` executable is in your environment's `$PATH`
80
93
  variable. If you'd like to set an explicit path to the `pandoc` executable,
81
94
  you can do so with `PandocRuby.pandoc_path = '/path/to/pandoc'`
82
95
 
@@ -108,20 +121,17 @@ used to modify the behavior of readers and writers. To use an extension,
108
121
  add the extension with a `+` or `-` after the reader or writer name:
109
122
 
110
123
  ```ruby
111
- # Without extension
124
+ # Without extension:
112
125
  PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict').to_html
113
126
  # => "<p>Line 1</p>\n<h1>Heading</h1>\n"
114
127
 
115
- # With extension:
116
- >> PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
128
+ # With `+blank_before_header` extension:
129
+ PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
117
130
  # => "<p>Line 1 # Heading</p>\n
118
131
  ```
119
132
 
120
133
  ### More Information
121
134
 
122
- Available format readers and writers are available in the `PandocRuby::READERS`
123
- and `PandocRuby::WRITERS` constants.
124
-
125
135
  For more information on Pandoc, see the
126
136
  [Pandoc documentation](http://johnmacfarlane.net/pandoc/)
127
137
  or run `man pandoc`
data/lib/pandoc-ruby.rb CHANGED
@@ -3,7 +3,11 @@ require 'tempfile'
3
3
  require 'timeout'
4
4
 
5
5
  class PandocRuby
6
- @@pandoc_path = 'pandoc'
6
+ # Use the pandoc command with a custom executable path.
7
+ @pandoc_path = 'pandoc'
8
+ class << self
9
+ attr_accessor :pandoc_path
10
+ end
7
11
 
8
12
  # The available readers and their corresponding names. The keys are used to
9
13
  # generate methods and specify options to Pandoc.
@@ -112,12 +116,6 @@ class PandocRuby
112
116
  # All of the available Writers.
113
117
  WRITERS = STRING_WRITERS.merge(BINARY_WRITERS)
114
118
 
115
- # To use run the pandoc command with a custom executable path, the path
116
- # to the pandoc executable can be set here.
117
- def self.pandoc_path=(path)
118
- @@pandoc_path = path
119
- end
120
-
121
119
  # A shortcut method that creates a new PandocRuby object and immediately
122
120
  # calls `#convert`. Options passed to this method are passed directly to
123
121
  # `#new` and treated the same as if they were passed directly to the
@@ -127,23 +125,27 @@ class PandocRuby
127
125
  end
128
126
 
129
127
  attr_writer :binary_output
128
+
130
129
  def binary_output
131
- @binary_output ||= false
130
+ @binary_output ||= false
132
131
  end
133
132
 
134
133
  attr_writer :options
134
+
135
135
  def options
136
- @options ||= []
136
+ @options ||= []
137
137
  end
138
138
 
139
139
  attr_writer :option_string
140
+
140
141
  def option_string
141
- @option_string ||= ''
142
+ @option_string ||= ''
142
143
  end
143
144
 
144
145
  attr_writer :writer
146
+
145
147
  def writer
146
- @writer ||= 'html'
148
+ @writer ||= 'html'
147
149
  end
148
150
 
149
151
  attr_accessor :input_files
@@ -159,11 +161,13 @@ class PandocRuby
159
161
  # new(["/path/to/file.md"], :option1 => :value, :option2)
160
162
  # new(["/to/file1.html", "/to/file2.html"], :option1 => :value)
161
163
  def initialize(*args)
162
- if args[0].is_a?(String)
164
+ case args[0]
165
+ when String
163
166
  self.input_string = args.shift
164
- elsif args[0].is_a?(Array)
165
- self.input_files = args.shift.join(' ')
167
+ when Array
168
+ self.input_files = args.shift.join(' ')
166
169
  end
170
+
167
171
  self.options = args
168
172
  end
169
173
 
@@ -179,8 +183,9 @@ class PandocRuby
179
183
  # PandocRuby.new("# text").convert
180
184
  # # => "<h1 id=\"text\">text</h1>\n"
181
185
  def convert(*args)
182
- self.options += args if args
183
- self.option_string = prepare_options(self.options)
186
+ self.options += args if args
187
+ self.option_string = prepare_options(self.options)
188
+
184
189
  if self.binary_output
185
190
  convert_binary
186
191
  else
@@ -201,6 +206,7 @@ class PandocRuby
201
206
  READERS.each_key do |r|
202
207
  define_method(r) do |*args|
203
208
  args += [{ :from => r }]
209
+
204
210
  new(*args)
205
211
  end
206
212
  end
@@ -218,6 +224,7 @@ class PandocRuby
218
224
  WRITERS.each_key do |w|
219
225
  define_method(:"to_#{w}") do |*args|
220
226
  args += [{ :to => w.to_sym }]
227
+
221
228
  convert(*args)
222
229
  end
223
230
  end
@@ -229,13 +236,17 @@ class PandocRuby
229
236
  # temp file is closed and unlinked.
230
237
  def convert_binary
231
238
  tmp_file = Tempfile.new('pandoc-conversion')
239
+
232
240
  begin
233
- self.options += [{ :output => tmp_file.path }]
234
- self.option_string = "#{self.option_string} --output #{tmp_file.path}"
241
+ self.options += [{ :output => tmp_file.path }]
242
+ self.option_string = "#{self.option_string} --output \"#{tmp_file.path}\""
243
+
235
244
  execute_pandoc
245
+
236
246
  return IO.binread(tmp_file)
237
247
  ensure
238
248
  tmp_file.close
249
+
239
250
  tmp_file.unlink
240
251
  end
241
252
  end
@@ -248,30 +259,33 @@ class PandocRuby
248
259
  # Wrapper to run pandoc in a consistent, DRY way
249
260
  def execute_pandoc
250
261
  if !self.input_files.nil?
251
- execute("#{@@pandoc_path} #{self.input_files}#{self.option_string}")
262
+ execute("#{PandocRuby.pandoc_path} #{self.input_files}#{self.option_string}")
252
263
  else
253
- execute("#{@@pandoc_path}#{self.option_string}")
264
+ execute("#{PandocRuby.pandoc_path}#{self.option_string}")
254
265
  end
255
266
  end
256
267
 
257
268
  # Run the command and returns the output.
258
269
  def execute(command)
259
270
  output = error = exit_status = nil
260
- @timeout ||= 31_557_600 # A year should be enough?
271
+
272
+ @timeout ||= 31_557_600
273
+
261
274
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
262
- begin
263
- Timeout.timeout(@timeout) do
264
- stdin.puts self.input_string
265
- stdin.close
266
- output = stdout.read
267
- error = stderr.read
268
- exit_status = wait_thr.value
269
- end
270
- rescue Timeout::Error => ex
271
- Process.kill 9, wait_thr.pid
272
- maybe_ex = "\n#{ex}" if ex
273
- error = "Pandoc timed out after #{@timeout} seconds.#{maybe_ex}"
275
+ Timeout.timeout(@timeout) do
276
+ stdin.puts self.input_string
277
+
278
+ stdin.close
279
+
280
+ output = stdout.read
281
+ error = stderr.read
282
+ exit_status = wait_thr.value
274
283
  end
284
+ rescue Timeout::Error => ex
285
+ Process.kill 9, wait_thr.pid
286
+
287
+ maybe_ex = "\n#{ex}" if ex
288
+ error = "Pandoc timed out after #{@timeout} seconds.#{maybe_ex}"
275
289
  end
276
290
 
277
291
  raise error unless exit_status && exit_status.success?
@@ -303,10 +317,10 @@ class PandocRuby
303
317
  set_pandoc_ruby_options(flag, argument)
304
318
  return '' if flag == 'timeout' # pandoc doesn't accept timeouts yet
305
319
 
306
- if !argument.nil?
307
- "#{format_flag(flag)} #{argument}"
308
- else
320
+ if argument.nil?
309
321
  format_flag(flag)
322
+ else
323
+ "#{format_flag(flag)} \"#{argument}\""
310
324
  end
311
325
  end
312
326
 
@@ -315,6 +329,8 @@ class PandocRuby
315
329
  def format_flag(flag)
316
330
  if flag.length == 1
317
331
  " -#{flag}"
332
+ elsif flag =~ /^-|\+/
333
+ " #{flag}"
318
334
  else
319
335
  " --#{flag.to_s.tr('_', '-')}"
320
336
  end
@@ -325,8 +341,8 @@ class PandocRuby
325
341
  def set_pandoc_ruby_options(flag, argument = nil)
326
342
  case flag
327
343
  when 't', 'to'
328
- self.writer = argument.to_s
329
- self.binary_output = true if BINARY_WRITERS.key?(self.writer)
344
+ self.writer = argument.to_s
345
+ self.binary_output = true if BINARY_WRITERS.key?(self.writer)
330
346
  when 'timeout'
331
347
  @timeout = argument
332
348
  end
data/pandoc-ruby.gemspec CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'pandoc-ruby'
8
- s.version = '2.1.1'
8
+ s.version = '2.1.5'
9
9
  s.authors = ['William Melody']
10
- s.date = '2020-03-23'
10
+ s.date = '2021-11-13'
11
11
  s.description = 'Ruby wrapper for Pandoc'
12
12
  s.email = 'hi@williammelody.com'
13
13
  s.extra_rdoc_files = [
@@ -23,7 +23,8 @@ describe 'Conversions' do
23
23
  :from => from,
24
24
  :to => to
25
25
  )
26
- assert_equal(converted_content.strip, to_content.strip)
26
+
27
+ assert_equal(to_content.strip, converted_content.strip)
27
28
  end
28
29
  end
29
30
  end
@@ -47,7 +48,7 @@ describe 'Conversions' do
47
48
  )
48
49
  end
49
50
 
50
- assert_match(/couldn't parse docx file/, error.message)
51
+ assert_match(/couldn't unpack docx container/, error.message)
51
52
  end
52
53
 
53
54
  it "raises an error when attempting to convert doc with doc format" do
@@ -2,10 +2,10 @@ require 'helper'
2
2
 
3
3
  describe PandocRuby do
4
4
  before do
5
- @file = File.join(File.dirname(__FILE__), 'files', 'test.md')
6
- @file2 = File.join(File.dirname(__FILE__), 'files', 'test2.md')
7
- @string = '# Test String'
8
- @converter = PandocRuby.new(@string, :t => :rst)
5
+ @file = File.join(File.dirname(__FILE__), 'files', 'test.md')
6
+ @file2 = File.join(File.dirname(__FILE__), 'files', 'test2.md')
7
+ @string = '# Test String'
8
+ @converter = PandocRuby.new(@string, :t => :rst)
9
9
  end
10
10
 
11
11
  after do
@@ -14,15 +14,20 @@ describe PandocRuby do
14
14
 
15
15
  it 'calls bare pandoc when passed no options' do
16
16
  converter = PandocRuby.new(@string)
17
+
17
18
  converter.expects(:execute).with('pandoc').returns(true)
19
+
18
20
  assert converter.convert
19
21
  end
20
22
 
21
23
  it 'converts with altered pandoc_path' do
22
24
  path = '/usr/bin/env pandoc'
23
25
  PandocRuby.pandoc_path = path
26
+
24
27
  converter = PandocRuby.new(@string)
28
+
25
29
  converter.expects(:execute).with(path).returns(true)
30
+
26
31
  assert converter.convert
27
32
  end
28
33
 
@@ -45,50 +50,79 @@ describe PandocRuby do
45
50
  end
46
51
 
47
52
  it 'accepts short options' do
48
- @converter.expects(:execute).with('pandoc -t rst').returns(true)
53
+ @converter.expects(:execute).with('pandoc -t "rst"').returns(true)
54
+
49
55
  assert @converter.convert
50
56
  end
51
57
 
52
58
  it 'accepts long options' do
53
59
  converter = PandocRuby.new(@string, :to => :rst)
54
- converter.expects(:execute).with('pandoc --to rst').returns(true)
60
+
61
+ converter.expects(:execute).with('pandoc --to "rst"').returns(true)
62
+
55
63
  assert converter.convert
56
64
  end
57
65
 
58
66
  it 'accepts a variety of options in initializer' do
59
- converter = PandocRuby.new(@string, :s, {
60
- :f => :markdown, :to => :rst
61
- }, 'no-wrap')
62
- converter \
63
- .expects(:execute) \
64
- .with('pandoc -s -f markdown --to rst --no-wrap') \
67
+ converter = PandocRuby.new(
68
+ @string,
69
+ :s,
70
+ { :f => :markdown, :to => :rst },
71
+ 'no-wrap'
72
+ )
73
+
74
+ converter \
75
+ .expects(:execute) \
76
+ .with('pandoc -s -f "markdown" --to "rst" --no-wrap') \
65
77
  .returns(true)
78
+
66
79
  assert converter.convert
67
80
  end
68
81
 
69
82
  it 'accepts a variety of options in convert' do
70
83
  converter = PandocRuby.new(@string)
71
- converter \
72
- .expects(:execute) \
73
- .with('pandoc -s -f markdown --to rst --no-wrap') \
84
+
85
+ converter \
86
+ .expects(:execute) \
87
+ .with('pandoc -s -f "markdown" --to "rst" --no-wrap') \
74
88
  .returns(true)
89
+
75
90
  assert converter.convert(:s, { :f => :markdown, :to => :rst }, 'no-wrap')
76
91
  end
77
92
 
78
93
  it 'converts underscore symbol args to hyphenated long options' do
79
- converter = PandocRuby.new(@string, {
80
- :email_obfuscation => :javascript
81
- }, :table_of_contents)
82
- converter \
83
- .expects(:execute) \
84
- .with('pandoc --email-obfuscation javascript --table-of-contents') \
94
+ converter = PandocRuby.new(
95
+ @string,
96
+ { :email_obfuscation => :javascript },
97
+ :table_of_contents
98
+ )
99
+
100
+ converter \
101
+ .expects(:execute) \
102
+ .with('pandoc --email-obfuscation "javascript" --table-of-contents') \
85
103
  .returns(true)
104
+
86
105
  assert converter.convert
87
106
  end
88
107
 
89
108
  it 'uses second arg as option' do
90
109
  converter = PandocRuby.new(@string, 'toc')
110
+
91
111
  converter.expects(:execute).with('pandoc --toc').returns(true)
112
+
113
+ assert converter.convert
114
+ end
115
+
116
+ it 'passes command line options without modification' do
117
+ converter = PandocRuby.new(
118
+ @string,
119
+ '+RTS', '-M512M', '-RTS', '--to=markdown', '--no-wrap'
120
+ )
121
+
122
+ converter.expects(:execute).with(
123
+ 'pandoc +RTS -M512M -RTS --to=markdown --no-wrap'
124
+ ).returns(true)
125
+
92
126
  assert converter.convert
93
127
  end
94
128
 
@@ -101,6 +135,7 @@ describe PandocRuby do
101
135
  ),
102
136
  "<p>Line 1</p>\n<h1>Heading</h1>\n"
103
137
  )
138
+
104
139
  assert_equal(
105
140
  PandocRuby.convert(
106
141
  "Line 1\n# Heading",
@@ -120,6 +155,7 @@ describe PandocRuby do
120
155
  ),
121
156
  "~example~\n"
122
157
  )
158
+
123
159
  assert_equal(
124
160
  PandocRuby.convert(
125
161
  "<sub>example</sub>\n",
@@ -130,6 +166,89 @@ describe PandocRuby do
130
166
  )
131
167
  end
132
168
 
169
+ it 'supports output filenames without spaces' do
170
+ Tempfile.create('example') do |file|
171
+ PandocRuby.convert(
172
+ '# Example',
173
+ :from => 'markdown',
174
+ :to => 'html',
175
+ :output => file.path
176
+ )
177
+
178
+ file.rewind
179
+
180
+ assert_equal("<h1 id=\"example\">Example</h1>\n", file.read)
181
+ end
182
+ end
183
+
184
+ it 'quotes output filenames with spaces' do
185
+ Tempfile.create('example with spaces') do |file|
186
+ converter = PandocRuby.new(
187
+ '# Example',
188
+ :from => 'markdown',
189
+ :to => 'html',
190
+ :output => file.path
191
+ )
192
+
193
+ converter \
194
+ .expects(:execute) \
195
+ .with(
196
+ "pandoc --from \"markdown\" --to \"html\" --output \"#{file.path}\""
197
+ ).returns(true)
198
+
199
+ assert converter.convert
200
+ end
201
+ end
202
+
203
+ it 'outputs to filenames with spaces' do
204
+ Tempfile.create('example with spaces') do |file|
205
+ PandocRuby.convert(
206
+ '# Example',
207
+ :from => 'markdown',
208
+ :to => 'html',
209
+ :output => file.path
210
+ )
211
+
212
+ file.rewind
213
+
214
+ assert_equal("<h1 id=\"example\">Example</h1>\n", file.read)
215
+ end
216
+ end
217
+
218
+ it 'quotes output filenames as Pathname objects' do
219
+ Tempfile.create('example with spaces') do |file|
220
+ converter = PandocRuby.new(
221
+ '# Example',
222
+ :from => 'markdown',
223
+ :to => 'html',
224
+ :output => Pathname.new(file.path)
225
+ )
226
+
227
+ converter \
228
+ .expects(:execute) \
229
+ .with(
230
+ "pandoc --from \"markdown\" --to \"html\" --output \"#{file.path}\""
231
+ ).returns(true)
232
+
233
+ assert converter.convert
234
+ end
235
+ end
236
+
237
+ it 'outputs to filenames as Pathname objects' do
238
+ Tempfile.create('example with spaces') do |file|
239
+ PandocRuby.convert(
240
+ '# Example',
241
+ :from => 'markdown',
242
+ :to => 'html',
243
+ :output => Pathname.new(file.path)
244
+ )
245
+
246
+ file.rewind
247
+
248
+ assert_equal("<h1 id=\"example\">Example</h1>\n", file.read)
249
+ end
250
+ end
251
+
133
252
  it 'raises RuntimeError from pandoc executable error' do
134
253
  assert_raises(RuntimeError) do
135
254
  PandocRuby.new('# hello', 'badopt').to_html5
@@ -139,7 +258,9 @@ describe PandocRuby do
139
258
  PandocRuby::READERS.each_key do |r|
140
259
  it "converts from #{r} with PandocRuby.#{r}" do
141
260
  converter = PandocRuby.send(r, @string)
142
- converter.expects(:execute).with("pandoc --from #{r}").returns(true)
261
+
262
+ converter.expects(:execute).with("pandoc --from \"#{r}\"").returns(true)
263
+
143
264
  assert converter.convert
144
265
  end
145
266
  end
@@ -147,10 +268,12 @@ describe PandocRuby do
147
268
  PandocRuby::STRING_WRITERS.each_key do |w|
148
269
  it "converts to #{w} with to_#{w}" do
149
270
  converter = PandocRuby.new(@string)
150
- converter \
151
- .expects(:execute) \
152
- .with("pandoc --no-wrap --to #{w}") \
271
+
272
+ converter \
273
+ .expects(:execute) \
274
+ .with("pandoc --no-wrap --to \"#{w}\"") \
153
275
  .returns(true)
276
+
154
277
  assert converter.send("to_#{w}", :no_wrap)
155
278
  end
156
279
  end
@@ -158,26 +281,31 @@ describe PandocRuby do
158
281
  PandocRuby::BINARY_WRITERS.each_key do |w|
159
282
  it "converts to #{w} with to_#{w}" do
160
283
  converter = PandocRuby.new(@string)
161
- converter \
162
- .expects(:execute) \
163
- .with(regexp_matches(/^pandoc --no-wrap --to #{w} --output /)) \
284
+
285
+ converter \
286
+ .expects(:execute) \
287
+ .with(regexp_matches(/^pandoc --no-wrap --to "#{w}" --output /)) \
164
288
  .returns(true)
289
+
165
290
  assert converter.send("to_#{w}", :no_wrap)
166
291
  end
167
292
  end
168
293
 
169
294
  it 'works with strings' do
170
295
  converter = PandocRuby.new('## this is a title')
296
+
171
297
  assert_match(/h2/, converter.convert)
172
298
  end
173
299
 
174
300
  it 'accepts blank strings' do
175
301
  converter = PandocRuby.new('')
302
+
176
303
  assert_match("\n", converter.convert)
177
304
  end
178
305
 
179
306
  it 'accepts nil and treats like a blank string' do
180
307
  converter = PandocRuby.new(nil)
308
+
181
309
  assert_match("\n", converter.convert)
182
310
  end
183
311
 
@@ -190,21 +318,20 @@ describe PandocRuby do
190
318
  end
191
319
 
192
320
  it 'runs more than 400 times without error' do
193
- begin
194
- 400.times do
195
- PandocRuby.convert(@string)
196
- end
197
- assert true
198
- rescue Errno::EMFILE, Errno::EAGAIN => e
199
- flunk e
321
+ 400.times do
322
+ PandocRuby.convert(@string)
200
323
  end
324
+
325
+ assert true
326
+ rescue Errno::EMFILE, Errno::EAGAIN => e
327
+ flunk e
201
328
  end
202
329
 
203
330
  it 'gracefully times out when pandoc hangs due to malformed input' do
204
- skip(%(
205
- Pandoc no longer times out with test file. Determine how to test.
206
- ))
331
+ skip('Pandoc no longer times out with test file. Determine how to test.')
332
+
207
333
  file = File.join(File.dirname(__FILE__), 'files', 'bomb.tex')
334
+
208
335
  contents = File.read(file)
209
336
 
210
337
  assert_raises(RuntimeError) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandoc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Melody
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-23 00:00:00.000000000 Z
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby wrapper for Pandoc
14
14
  email: hi@williammelody.com
@@ -36,7 +36,7 @@ homepage: http://github.com/xwmx/pandoc-ruby
36
36
  licenses:
37
37
  - MIT
38
38
  metadata: {}
39
- post_install_message:
39
+ post_install_message:
40
40
  rdoc_options: []
41
41
  require_paths:
42
42
  - lib
@@ -51,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.1.2
55
- signing_key:
54
+ rubygems_version: 3.2.22
55
+ signing_key:
56
56
  specification_version: 4
57
57
  summary: PandocRuby
58
58
  test_files: []