pandocomatic 0.2.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pandocomatic/cli.rb +81 -64
  3. data/lib/pandocomatic/command/command.rb +37 -35
  4. data/lib/pandocomatic/command/convert_dir_command.rb +44 -46
  5. data/lib/pandocomatic/command/convert_file_command.rb +314 -290
  6. data/lib/pandocomatic/command/convert_file_multiple_command.rb +56 -53
  7. data/lib/pandocomatic/command/convert_list_command.rb +31 -34
  8. data/lib/pandocomatic/command/copy_file_command.rb +14 -15
  9. data/lib/pandocomatic/command/create_link_command.rb +24 -27
  10. data/lib/pandocomatic/command/skip_command.rb +12 -15
  11. data/lib/pandocomatic/configuration.rb +682 -867
  12. data/lib/pandocomatic/default_configuration.yaml +4 -0
  13. data/lib/pandocomatic/error/cli_error.rb +30 -26
  14. data/lib/pandocomatic/error/configuration_error.rb +10 -9
  15. data/lib/pandocomatic/error/io_error.rb +13 -13
  16. data/lib/pandocomatic/error/pandoc_error.rb +10 -9
  17. data/lib/pandocomatic/error/pandocomatic_error.rb +15 -14
  18. data/lib/pandocomatic/error/processor_error.rb +9 -9
  19. data/lib/pandocomatic/error/template_error.rb +50 -0
  20. data/lib/pandocomatic/input.rb +53 -54
  21. data/lib/pandocomatic/multiple_files_input.rb +79 -72
  22. data/lib/pandocomatic/output.rb +29 -0
  23. data/lib/pandocomatic/pandoc_metadata.rb +193 -181
  24. data/lib/pandocomatic/pandocomatic.rb +101 -97
  25. data/lib/pandocomatic/pandocomatic_yaml.rb +69 -0
  26. data/lib/pandocomatic/path.rb +171 -0
  27. data/lib/pandocomatic/printer/command_printer.rb +7 -5
  28. data/lib/pandocomatic/printer/configuration_errors_printer.rb +7 -6
  29. data/lib/pandocomatic/printer/error_printer.rb +12 -7
  30. data/lib/pandocomatic/printer/finish_printer.rb +11 -10
  31. data/lib/pandocomatic/printer/help_printer.rb +8 -6
  32. data/lib/pandocomatic/printer/printer.rb +34 -34
  33. data/lib/pandocomatic/printer/summary_printer.rb +39 -33
  34. data/lib/pandocomatic/printer/version_printer.rb +8 -8
  35. data/lib/pandocomatic/printer/views/cli_error.txt +5 -0
  36. data/lib/pandocomatic/printer/views/configuration_error.txt +2 -1
  37. data/lib/pandocomatic/printer/views/error.txt +1 -1
  38. data/lib/pandocomatic/printer/views/finish.txt +1 -1
  39. data/lib/pandocomatic/printer/views/help.txt +27 -15
  40. data/lib/pandocomatic/printer/views/summary.txt +7 -1
  41. data/lib/pandocomatic/printer/views/template_error.txt +1 -0
  42. data/lib/pandocomatic/printer/views/version.txt +3 -3
  43. data/lib/pandocomatic/printer/views/warning.txt +1 -1
  44. data/lib/pandocomatic/printer/warning_printer.rb +21 -19
  45. data/lib/pandocomatic/processor.rb +28 -28
  46. data/lib/pandocomatic/processors/fileinfo_preprocessor.rb +35 -30
  47. data/lib/pandocomatic/processors/metadata_preprocessor.rb +23 -22
  48. data/lib/pandocomatic/template.rb +244 -0
  49. data/lib/pandocomatic/warning.rb +24 -25
  50. metadata +32 -12
@@ -1,333 +1,357 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
3
- #
4
+ # Copyright 2017-2022, Huub de Beer <Huub@heerdebeer.org>
5
+ #
4
6
  # This file is part of pandocomatic.
5
- #
7
+ #
6
8
  # Pandocomatic is free software: you can redistribute it and/or modify
7
9
  # it under the terms of the GNU General Public License as published by the
8
10
  # Free Software Foundation, either version 3 of the License, or (at your
9
11
  # option) any later version.
10
- #
12
+ #
11
13
  # Pandocomatic is distributed in the hope that it will be useful, but
12
14
  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
15
  # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
16
  # for more details.
15
- #
17
+ #
16
18
  # You should have received a copy of the GNU General Public License along
17
19
  # with pandocomatic. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Pandocomatic
20
-
21
- require 'paru'
22
- require 'shellwords'
23
-
24
- require_relative '../pandoc_metadata.rb'
25
-
26
- require_relative '../processor.rb'
27
- require_relative '../processors/fileinfo_preprocessor'
28
- require_relative '../processors/metadata_preprocessor'
29
-
30
- require_relative '../configuration.rb'
31
-
32
- require_relative '../error/io_error.rb'
33
- require_relative '../error/configuration_error.rb'
34
- require_relative '../error/processor_error.rb'
35
-
36
- require_relative 'command.rb'
37
-
38
- # Output formats used in pandocomatic
39
- OUTPUT_FORMATS = ["docx", "pptx", "odt", "pdf", "epub", "epub3", "epub2"]
40
-
41
- # Command to convert a file
42
- #
43
- # @!attribute config
44
- # @return [Configuration] the configuration of pandocomatic used to
45
- # convert the file
46
- #
47
- # @!attribute src
48
- # @return [String] the path to the file to convert
22
+ require 'paru'
23
+ require 'shellwords'
24
+
25
+ require_relative 'command'
26
+ require_relative '../error/io_error'
27
+ require_relative '../error/configuration_error'
28
+ require_relative '../error/processor_error'
29
+ require_relative '../pandoc_metadata'
30
+ require_relative '../path'
31
+ require_relative '../processor'
32
+ require_relative '../processors/fileinfo_preprocessor'
33
+ require_relative '../processors/metadata_preprocessor'
34
+ require_relative '../template'
35
+
36
+ # Output formats used in pandocomatic
37
+ OUTPUT_FORMATS = %w[docx pptx odt pdf epub epub3 epub2].freeze
38
+
39
+ # Pandoc options that take a path as argument
40
+ PANDOC_OPTIONS_WITH_PATH = %w[
41
+ data-dir
42
+ filter
43
+ template
44
+ css
45
+ include-in-header
46
+ include-before-body
47
+ include-after-body
48
+ reference-odt
49
+ reference-docx
50
+ epub-stylesheet
51
+ epub-cover-image
52
+ epub-metadata
53
+ epub-embed-font
54
+ epub-subdirectory
55
+ bibliography
56
+ csl
57
+ syntax-definition
58
+ reference-doc
59
+ lua-filter
60
+ extract-media
61
+ resource-path
62
+ citation-abbreviations
63
+ abbreviations
64
+ log
65
+ resource-path
66
+ ].freeze
67
+
68
+ # rubocop:disable Metrics
69
+
70
+ # Command to convert a file
71
+ #
72
+ # @!attribute config
73
+ # @return [Configuration] the configuration of pandocomatic used to
74
+ # convert the file
75
+ #
76
+ # @!attribute src
77
+ # @return [String] the path to the file to convert
78
+ #
79
+ # @!attribute dst
80
+ # @return [String] the path to the output file
81
+ class ConvertFileCommand < Command
82
+ attr_reader :config, :src, :dst
83
+
84
+ # Create a new ConvertFileCommand
49
85
  #
50
- # @!attribute dst
51
- # @return [String] the path to the output file
52
- class ConvertFileCommand < Command
53
-
54
- attr_reader :config, :src, :dst
55
-
56
- # Create a new ConvertFileCommand
57
- #
58
- # @param config [Configuration] pandocomatic's configuration
59
- # @param src [String] the path to the file to convert
60
- # @param dst [String] the path to save the output of the conversion
61
- # @param template_name [String = nil] the template to use while converting
62
- # this file
63
- def initialize(config, src, dst, template_name = nil)
64
- super()
65
-
66
- @config = config
67
- @src = src
68
- @dst = dst
69
-
70
- if template_name.nil? or template_name.empty?
71
- @template_name = @config.determine_template @src
72
- else
73
- @template_name = template_name
74
- end
75
-
76
- @metadata = PandocMetadata.load_file @src
77
- @dst = @config.set_destination @dst, @template_name, @metadata
86
+ # @param config [Configuration] pandocomatic's configuration
87
+ # @param src [String] the path to the file to convert
88
+ # @param dst [String] the path to save the output of the conversion
89
+ # @param template_name [String = nil] the template to use while converting
90
+ # this file
91
+ def initialize(config, src, dst, template_name = nil)
92
+ super()
93
+
94
+ @config = config
95
+ @src = src
96
+ @dst = dst
97
+
98
+ @template_name = if template_name.nil? || template_name.empty?
99
+ @config.determine_template @src
100
+ else
101
+ template_name
102
+ end
103
+
104
+ @metadata = PandocMetadata.load_file @src
105
+ @dst = @config.set_destination @dst, @template_name, @metadata
106
+
107
+ @errors.push IOError.new(:file_does_not_exist, nil, @src) unless File.exist? @src
108
+ @errors.push IOError.new(:file_is_not_a_file, nil, @src) unless File.file? @src
109
+ @errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src
110
+ end
78
111
 
79
- @errors.push IOError.new(:file_does_not_exist, nil, @src) unless File.exist? @src
80
- @errors.push IOError.new(:file_is_not_a_file, nil, @src) unless File.file? @src
81
- @errors.push IOError.new(:file_is_not_readable, nil, @src) unless File.readable? @src
82
- end
112
+ # Execute this ConvertFileCommand
113
+ def run
114
+ convert_file
115
+ end
83
116
 
84
- # Execute this ConvertFileCommand
85
- def run
86
- convert_file
87
- end
117
+ # Create a string representation of this ConvertFileCommand
118
+ #
119
+ # @return [String]
120
+ def to_s
121
+ str = "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
122
+ unless @metadata.unique?
123
+ str += "\n\t encountered multiple YAML metadata blocks with a pandocomatic property."\
124
+ ' Only the pandocomatic property in the first YAML metadata block is being used;'\
125
+ ' the others are discarded.'
126
+ end
127
+ str
128
+ end
88
129
 
89
- # Create a string representation of this ConvertFileCommand
90
- #
91
- # @return [String]
92
- def to_s
93
- str = "convert #{File.basename @src} #{"-> #{File.basename @dst}" unless @dst.nil?}"
94
- str += "\n\t encountered multiple YAML metadata blocks with a pandocomatic propertie. Only the pandocomatic property in the first YAML metadata block is being used; the others are discarded." unless @metadata.unique?
95
- str
96
- end
130
+ private
97
131
 
98
- private
132
+ INTERNAL_TEMPLATE = 'internal template'
99
133
 
100
- def convert_file
101
- pandoc_options = @metadata.pandoc_options || {}
102
- template = {}
134
+ def convert_file
135
+ pandoc_options = @metadata.pandoc_options || {}
136
+ template = nil
103
137
 
104
- # Determine the actual options and settings to use when converting this
105
- # file.
106
- if not @template_name.nil? and not @template_name.empty?
107
- raise ConfigurationError.new(:no_such_template, nil, @template_name) unless @config.has_template? @template_name
108
- template = @config.get_template @template_name
138
+ # Determine the actual options and settings to use when converting this
139
+ # file.
140
+ if !@template_name.nil? && !@template_name.empty?
141
+ unless @config.template? @template_name
142
+ raise ConfigurationError.new(:no_such_template, nil,
143
+ @template_name)
144
+ end
109
145
 
110
- pandoc_options = Configuration.extend_value(pandoc_options, template['pandoc'])
111
- end
112
-
113
- # Write out the results of the conversion process to file.
114
- if @dst.to_s.empty? and @metadata.pandoc_options.has_key? 'output'
115
- @dst = @metadata.pandoc_options['output']
146
+ template = @config.get_template @template_name
147
+ pandoc_options = Template.extend_value(pandoc_options, template.pandoc)
148
+ else
149
+ template = Template.new INTERNAL_TEMPLATE
150
+ end
151
+
152
+ # Ignore the `--verbose` option, and warn about ignoring it
153
+ if pandoc_options.key? 'verbose'
154
+ pandoc_options.delete 'verbose'
155
+ warn 'WARNING: Ignoring the pandoc option --verbose because it'\
156
+ ' might interfere with the working of pandocomatic.'
157
+ end
158
+
159
+ template.merge! Template.new(INTERNAL_TEMPLATE, @metadata.pandocomatic) if @metadata.pandocomatic?
160
+
161
+ # Write out the results of the conversion process to file.
162
+ @dst = @metadata.pandoc_options['output'] if @dst.to_s.empty? && @metadata.pandoc_options.key?('output')
163
+
164
+ # Run setup scripts
165
+ setup template
166
+
167
+ # Read in the file to convert
168
+ input = File.read @src
169
+
170
+ # Run the default preprocessors to mix-in information about the file
171
+ # that is being converted and mix-in the template's metadata section as
172
+ # well
173
+ input = FileInfoPreprocessor.run input, @src, src_root, pandoc_options
174
+ input = MetadataPreprocessor.run input, template.metadata if template.metadata?
175
+
176
+ # Convert the file by preprocessing it, run pandoc on it, and
177
+ # postprocessing the output
178
+ input = preprocess input, template
179
+ input = pandoc input, pandoc_options, File.dirname(@src)
180
+ output = postprocess input, template
181
+
182
+ begin
183
+ # Either output to file or to STDOUT.
184
+
185
+ if @config.stdout?
186
+ puts output
187
+ @dst.close!
188
+ else
189
+ unless use_output_option @dst
190
+ File.open(@dst, 'w') do |file|
191
+ raise IOError.new(:file_is_not_a_file, nil, @dst) unless File.file? @dst
192
+ raise IOError.new(:file_is_not_writable, nil, @dst) unless File.writable? @dst
193
+
194
+ file << output
116
195
  end
117
-
118
- template = Configuration.extend_value(@metadata.pandocomatic, template) if @metadata.has_pandocomatic?
119
-
120
- # Run setup scripts
121
- setup template
122
-
123
- # Read in the file to convert
124
- input = File.read @src
125
-
126
- # Run the default preprocessors to mix-in information about the file
127
- # that is being converted and mix-in the template's metadata section as
128
- # well
129
- input = FileInfoPreprocessor.run input, @src, src_root, pandoc_options
130
- input = MetadataPreprocessor.run input, template['metadata'] if template.has_key? 'metadata' and not template['metadata'].empty?
131
-
132
- # Convert the file by preprocessing it, run pandoc on it, and
133
- # postprocessing the output
134
- input = preprocess input, template
135
- input = pandoc input, pandoc_options, File.dirname(@src)
136
- output = postprocess input, template
137
-
138
- begin
139
- unless use_output_option @dst then
140
- File.open(@dst, 'w') do |file|
141
- raise IOError.new(:file_is_not_a_file, nil, @dst) unless File.file? @dst
142
- raise IOError.new(:file_is_not_writable, nil, @dst) unless File.writable? @dst
143
- file << output
144
- end
145
- end
146
- rescue StandardError => e
147
- raise IOError.new(:error_writing_file, e, @dst)
148
- end
149
-
150
- # run cleanup scripts
151
- cleanup template
196
+ end
152
197
  end
198
+ rescue StandardError => e
199
+ raise IOError.new(:error_writing_file, e, @dst)
200
+ end
153
201
 
154
- PANDOC_OPTIONS_WITH_PATH = [
155
- 'data-dir',
156
- 'filter',
157
- 'template',
158
- 'css',
159
- 'include-in-header',
160
- 'include-before-body',
161
- 'include-after-body',
162
- 'reference-odt',
163
- 'reference-docx',
164
- 'epub-stylesheet',
165
- 'epub-cover-image',
166
- 'epub-metadata',
167
- 'epub-embed-font',
168
- 'epub-subdirectory',
169
- 'bibliography',
170
- 'csl',
171
- 'syntax-definition',
172
- 'reference-doc',
173
- 'lua-filter',
174
- 'extract-media',
175
- 'resource-path',
176
- 'citation-abbreviations',
177
- 'abbreviations',
178
- 'log',
179
- 'resource-path'
180
- ]
181
-
182
- def pandoc(input, options, src_dir)
183
- absolute_dst = File.expand_path @dst
184
- Dir.chdir(src_dir) do
185
- converter = Paru::Pandoc.new
186
- options.each do |option, value|
187
- # Options come from a YAML string. In YAML, properties without a value get value nil.
188
- # Interpret these empty properties as "skip this property"
189
- next if value.nil?
190
-
191
- if PANDOC_OPTIONS_WITH_PATH.include? option
192
- is_executable = option == "filter"
193
- if value.is_a? Array
194
- value = value.map {|v| @config.update_path(v, src_dir, absolute_dst, is_executable)}
195
- else
196
- value = @config.update_path(value, src_dir, @dst, is_executable)
197
- end
198
- end
202
+ # run cleanup scripts
203
+ cleanup template
204
+ end
199
205
 
200
- # There is no "pdf" output format; change it to latex but keep the
201
- # extension.
202
- value = determine_output_for_pdf(options) if option == "to" and value == "pdf"
203
-
204
- begin
205
- # Pandoc multi-word options can have the multiple words separated by
206
- # both underscore (_) and dash (-).
207
- option = option.gsub "-", "_"
208
- converter.send option, value unless
209
- option == 'output' or
210
- option == 'use_extension' or
211
- option == 'rename'
212
- # don't let pandoc write the output to enable postprocessing
213
- rescue
214
- warn "The pandoc option '#{option}' (with value '#{value}') is not recognized by paru. This option is skipped." if debug?
206
+ def pandoc(input, options, src_dir)
207
+ absolute_dst = File.expand_path @dst
208
+ Dir.chdir(src_dir) do
209
+ converter = Paru::Pandoc.new
210
+ options.each do |option, value|
211
+ # Options come from a YAML string. In YAML, properties without a value get value nil.
212
+ # Interpret these empty properties as "skip this property"
213
+ next if value.nil?
214
+
215
+ if PANDOC_OPTIONS_WITH_PATH.include? option
216
+ executable = option == 'filter'
217
+ value = if value.is_a? Array
218
+ value.map { |v| Path.update_path(@config, v, absolute_dst, check_executable: executable) }
219
+ else
220
+ Path.update_path(@config, value, @dst, check_executable: executable)
215
221
  end
216
- end
217
-
218
- converter.send "output", absolute_dst if use_output_option absolute_dst
219
-
220
- begin
221
- puts converter.to_command if debug?
222
- converter << input
223
- rescue Paru::Error => e
224
- raise PandocError.new(:error_running_pandoc, e, input)
225
- end
222
+ end
223
+
224
+ # There is no "pdf" output format; change it to latex but keep the
225
+ # extension.
226
+ value = determine_output_for_pdf(options) if (option == 'to') && (value == 'pdf')
227
+
228
+ begin
229
+ # Pandoc multi-word options can have the multiple words separated by
230
+ # both underscore (_) and dash (-).
231
+ option = option.gsub '-', '_'
232
+ converter.send option, value unless
233
+ (option == 'output') ||
234
+ (option == 'use_extension') ||
235
+ (option == 'rename')
236
+ # don't let pandoc write the output to enable postprocessing
237
+ rescue StandardError
238
+ if debug?
239
+ warn "WARNING: The pandoc option '#{option}' (with value '#{value}')"\
240
+ ' is not recognized by paru. This option is skipped.'
226
241
  end
242
+ end
227
243
  end
228
244
 
229
- # Preprocess the input
230
- #
231
- # @param input [String] the input to preprocess
232
- # @param config [Hash] template
233
- #
234
- # @return [String] the generated output
235
- def preprocess(input, config = {})
236
- process input, 'preprocessors', config
237
- end
238
-
239
- # Postprocess the input
240
- #
241
- # @param input [String] the input to postprocess
242
- # @param config [Hash] template
243
- #
244
- # @return [String] the generated output
245
- def postprocess(input, config = {})
246
- process input, 'postprocessors', config
247
- end
245
+ converter.send 'output', absolute_dst if use_output_option absolute_dst
248
246
 
249
- # Run setup scripts
250
- #
251
- # @param config [Hash] template
252
- def setup(config = {})
253
- process "", 'setup', config
254
- end
255
-
256
- # Run cleanup scripts
257
- #
258
- # @param config [Hash] template
259
- def cleanup(config = {})
260
- process "", 'cleanup', config
247
+ begin
248
+ puts converter.to_command if debug?
249
+ converter << input
250
+ rescue Paru::Error => e
251
+ raise PandocError.new(:error_running_pandoc, e, input)
261
252
  end
253
+ end
254
+ end
262
255
 
263
- # Run the input string through a list of filters called processors. There
264
- # are various types: preprocessors and postprocessors, setup and
265
- # cleanup, and rename
266
- def process(input, type, config = {})
267
- if config.has_key? type then
268
- processors = config[type]
269
- output = input
270
- processors.each do |processor|
271
- script = if @config.is_local_path? processor
272
- processor
273
- else
274
- @config.update_path(processor, File.dirname(@src), @dst, true)
275
- end
276
-
277
- command, *parameters = script.shellsplit # split on spaces unless it is preceded by a backslash
278
-
279
- if not File.exists? command
280
- command = Configuration.which(command)
281
- script = "#{command} #{parameters.join(' ')}"
282
-
283
- raise ProcessorError.new(:script_does_not_exist, nil, command) if command.nil?
284
- end
256
+ # Preprocess the input
257
+ #
258
+ # @param input [String] the input to preprocess
259
+ # @param template [Template] template
260
+ #
261
+ # @return [String] the generated output
262
+ def preprocess(input, template)
263
+ process input, Template::PREPROCESSORS, template
264
+ end
285
265
 
286
- raise ProcessorError.new(:script_is_not_executable, nil, command) unless File.executable? command
266
+ # Postprocess the input
267
+ #
268
+ # @param input [String] the input to postprocess
269
+ # @param template [Template] template
270
+ #
271
+ # @return [String] the generated output
272
+ def postprocess(input, template)
273
+ process input, Template::POSTPROCESSORS, template
274
+ end
287
275
 
288
- begin
289
- output = Processor.run(script, output)
290
- rescue StandardError => e
291
- ProcessorError.new(:error_processing_script, e, [script, @src])
292
- end
293
- end
294
- output
295
- else
296
- input
297
- end
298
- end
276
+ # Run setup scripts
277
+ #
278
+ # @param template [Template] template
279
+ def setup(template)
280
+ process '', Template::SETUP, template
281
+ end
299
282
 
300
- private
283
+ # Run cleanup scripts
284
+ #
285
+ # @param template [Template] template
286
+ def cleanup(template)
287
+ process '', Template::CLEANUP, template
288
+ end
301
289
 
302
- def run_processor
290
+ # Run the input string through a list of filters called processors. There
291
+ # are various types: preprocessors and postprocessors, setup and
292
+ # cleanup, and rename
293
+ def process(input, type, template)
294
+ if template.send "#{type}?"
295
+ processors = template.send type
296
+ output = input
297
+ processors.each do |processor|
298
+ script = if Path.local_path? processor
299
+ processor
300
+ else
301
+ Path.update_path(@config, processor, @dst, check_executable: true)
302
+ end
303
+
304
+ command, *parameters = script.shellsplit # split on spaces unless it is preceded by a backslash
305
+
306
+ unless File.exist? command
307
+ command = Path.which(command)
308
+ script = "#{command} #{parameters.join(' ')}"
309
+
310
+ raise ProcessorError.new(:script_does_not_exist, nil, command) if command.nil?
311
+ end
312
+
313
+ raise ProcessorError.new(:script_is_not_executable, nil, command) unless File.executable? command
314
+
315
+ begin
316
+ output = Processor.run(script, output)
317
+ rescue StandardError => e
318
+ ProcessorError.new(:error_processing_script, e, [script, @src])
319
+ end
303
320
  end
321
+ output
322
+ else
323
+ input
324
+ end
325
+ end
304
326
 
305
- def use_output_option(dst)
306
- OUTPUT_FORMATS.include?(File.extname(dst).slice(1..-1))
307
- end
327
+ def use_output_option(dst)
328
+ OUTPUT_FORMATS.include?(File.extname(dst).slice(1..-1))
329
+ end
308
330
 
309
- # Pandoc version 2 supports multiple pdf engines. Determine which
310
- # to use given the options.
311
- #
312
- # @param options [Hash] the options to a paru pandoc converter
313
- # @return [String] the output format for the pdf engine to use.
314
- def determine_output_for_pdf(options)
315
- if options.has_key? 'pdf-engine'
316
- engine = options['pdf-engine']
317
- case engine
318
- when 'context'
319
- 'context'
320
- when 'pdfroff'
321
- 'ms'
322
- when 'wkhtmltopdf', 'weasyprint', 'prince'
323
- 'html'
324
- else
325
- 'latex'
326
- end
327
- else
328
- # According to pandoc's manual, the default is LaTeX
329
- 'latex'
330
- end
331
+ # Pandoc version 2 supports multiple pdf engines. Determine which
332
+ # to use given the options.
333
+ #
334
+ # @param options [Hash] the options to a paru pandoc converter
335
+ # @return [String] the output format for the pdf engine to use.
336
+ def determine_output_for_pdf(options)
337
+ if options.key? 'pdf-engine'
338
+ engine = options['pdf-engine']
339
+ case engine
340
+ when 'context'
341
+ 'context'
342
+ when 'pdfroff'
343
+ 'ms'
344
+ when 'wkhtmltopdf', 'weasyprint', 'prince'
345
+ 'html'
346
+ else
347
+ 'latex'
331
348
  end
349
+ else
350
+ # According to pandoc's manual, the default is LaTeX
351
+ 'latex'
352
+ end
332
353
  end
354
+ end
355
+
356
+ # rubocop:enable Metrics
333
357
  end