pandoc-ruby 2.1.2 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1463781defea383e2173516fdbcd675b94e344744f46eecdd902a075e0ec9be8
4
- data.tar.gz: 93e469307308ea223721b89c0084cbe5f05682417535956d3256653fa9824d7d
3
+ metadata.gz: 0fc72faf981a6e87e6ae3e6023dfd41111ee7fa8d72441a87eeb9c41ff0c0ed1
4
+ data.tar.gz: 1d8d925c3480800fee1701164081d96cdc8159b9dabb8008a6b19fdf678f4c05
5
5
  SHA512:
6
- metadata.gz: 5846c2d7a9dc807268512de610885fc6b10d1191273e85f229fced89bcec25e8b54faa05e8e5cc0660ee502cb5636dff0ac7eb4daa4b858ac676d97333f71476
7
- data.tar.gz: 3121cc63b9f2739cae06d85ed008b138c113332f72ca45bc6268ae782e86ae139f5fdc2192d065bce8c99d8bd73ff93dc87064c517b81d0b6c6d8393f5c7b66d
6
+ metadata.gz: ec5fd20766af6c1ba8beb17a885748850bf04c103bed37a1de9128e7b778f36553a7d93ef9d928a644830b33536247c6ea40f5af0c4f2301ef3531543d2fa8a9
7
+ data.tar.gz: 636bae03cfcf24bbb6404554917464c589856f3c2dd4f4dd5e44f5183c4396cf31a3459581bf42063bbcbc34a7dccfd2622e8a8984429f25d0a5dd82644b3373
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,29 +259,34 @@ 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
275
  begin
263
276
  Timeout.timeout(@timeout) do
264
277
  stdin.puts self.input_string
278
+
265
279
  stdin.close
266
- output = stdout.read
267
- error = stderr.read
280
+
281
+ output = stdout.read
282
+ error = stderr.read
268
283
  exit_status = wait_thr.value
269
284
  end
270
285
  rescue Timeout::Error => ex
271
286
  Process.kill 9, wait_thr.pid
272
- maybe_ex = "\n#{ex}" if ex
273
- error = "Pandoc timed out after #{@timeout} seconds.#{maybe_ex}"
287
+
288
+ maybe_ex = "\n#{ex}" if ex
289
+ error = "Pandoc timed out after #{@timeout} seconds.#{maybe_ex}"
274
290
  end
275
291
  end
276
292
 
@@ -305,10 +321,8 @@ class PandocRuby
305
321
 
306
322
  if argument.nil?
307
323
  format_flag(flag)
308
- elsif argument =~ /\s/
309
- "#{format_flag(flag)} '#{argument}'"
310
324
  else
311
- "#{format_flag(flag)} #{argument}"
325
+ "#{format_flag(flag)} \"#{argument}\""
312
326
  end
313
327
  end
314
328
 
@@ -317,6 +331,8 @@ class PandocRuby
317
331
  def format_flag(flag)
318
332
  if flag.length == 1
319
333
  " -#{flag}"
334
+ elsif flag =~ /^-|\+/
335
+ " #{flag}"
320
336
  else
321
337
  " --#{flag.to_s.tr('_', '-')}"
322
338
  end
@@ -327,8 +343,8 @@ class PandocRuby
327
343
  def set_pandoc_ruby_options(flag, argument = nil)
328
344
  case flag
329
345
  when 't', 'to'
330
- self.writer = argument.to_s
331
- self.binary_output = true if BINARY_WRITERS.key?(self.writer)
346
+ self.writer = argument.to_s
347
+ self.binary_output = true if BINARY_WRITERS.key?(self.writer)
332
348
  when 'timeout'
333
349
  @timeout = argument
334
350
  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.2'
8
+ s.version = '2.1.6'
9
9
  s.authors = ['William Melody']
10
- s.date = '2020-03-23'
10
+ s.date = '2021-11-22'
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",
@@ -138,12 +174,33 @@ describe PandocRuby do
138
174
  :to => 'html',
139
175
  :output => file.path
140
176
  )
177
+
141
178
  file.rewind
179
+
142
180
  assert_equal("<h1 id=\"example\">Example</h1>\n", file.read)
143
181
  end
144
182
  end
145
183
 
146
- it 'supports output filenames without spaces' do
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
147
204
  Tempfile.create('example with spaces') do |file|
148
205
  PandocRuby.convert(
149
206
  '# Example',
@@ -151,7 +208,43 @@ describe PandocRuby do
151
208
  :to => 'html',
152
209
  :output => file.path
153
210
  )
211
+
154
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
+
155
248
  assert_equal("<h1 id=\"example\">Example</h1>\n", file.read)
156
249
  end
157
250
  end
@@ -165,7 +258,9 @@ describe PandocRuby do
165
258
  PandocRuby::READERS.each_key do |r|
166
259
  it "converts from #{r} with PandocRuby.#{r}" do
167
260
  converter = PandocRuby.send(r, @string)
168
- converter.expects(:execute).with("pandoc --from #{r}").returns(true)
261
+
262
+ converter.expects(:execute).with("pandoc --from \"#{r}\"").returns(true)
263
+
169
264
  assert converter.convert
170
265
  end
171
266
  end
@@ -173,10 +268,12 @@ describe PandocRuby do
173
268
  PandocRuby::STRING_WRITERS.each_key do |w|
174
269
  it "converts to #{w} with to_#{w}" do
175
270
  converter = PandocRuby.new(@string)
176
- converter \
177
- .expects(:execute) \
178
- .with("pandoc --no-wrap --to #{w}") \
271
+
272
+ converter \
273
+ .expects(:execute) \
274
+ .with("pandoc --no-wrap --to \"#{w}\"") \
179
275
  .returns(true)
276
+
180
277
  assert converter.send("to_#{w}", :no_wrap)
181
278
  end
182
279
  end
@@ -184,26 +281,31 @@ describe PandocRuby do
184
281
  PandocRuby::BINARY_WRITERS.each_key do |w|
185
282
  it "converts to #{w} with to_#{w}" do
186
283
  converter = PandocRuby.new(@string)
187
- converter \
188
- .expects(:execute) \
189
- .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 /)) \
190
288
  .returns(true)
289
+
191
290
  assert converter.send("to_#{w}", :no_wrap)
192
291
  end
193
292
  end
194
293
 
195
294
  it 'works with strings' do
196
295
  converter = PandocRuby.new('## this is a title')
296
+
197
297
  assert_match(/h2/, converter.convert)
198
298
  end
199
299
 
200
300
  it 'accepts blank strings' do
201
301
  converter = PandocRuby.new('')
302
+
202
303
  assert_match("\n", converter.convert)
203
304
  end
204
305
 
205
306
  it 'accepts nil and treats like a blank string' do
206
307
  converter = PandocRuby.new(nil)
308
+
207
309
  assert_match("\n", converter.convert)
208
310
  end
209
311
 
@@ -220,6 +322,7 @@ describe PandocRuby do
220
322
  400.times do
221
323
  PandocRuby.convert(@string)
222
324
  end
325
+
223
326
  assert true
224
327
  rescue Errno::EMFILE, Errno::EAGAIN => e
225
328
  flunk e
@@ -227,10 +330,10 @@ describe PandocRuby do
227
330
  end
228
331
 
229
332
  it 'gracefully times out when pandoc hangs due to malformed input' do
230
- skip(%(
231
- Pandoc no longer times out with test file. Determine how to test.
232
- ))
333
+ skip('Pandoc no longer times out with test file. Determine how to test.')
334
+
233
335
  file = File.join(File.dirname(__FILE__), 'files', 'bomb.tex')
336
+
234
337
  contents = File.read(file)
235
338
 
236
339
  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.2
4
+ version: 2.1.6
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-22 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: []