pandocomatic 0.2.0.5 → 0.2.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8300ffdd25e759cb2192d95cf3d152b65618507b
|
4
|
+
data.tar.gz: 72e11c0aeb38ccc9d0e88f93e24132a70f500a3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d72562edd9458bf74660ac5c9446dfa861a79a66c79bf940a95deeada6034837fa4f9b28a5dd81f7a05d5fb82d9f47dcd68cf9a5edd2e59fb3d15e7aa8dd84e0
|
7
|
+
data.tar.gz: c6b9a79dced50944bd7003c2490c9d6cca3d07377f47b9acffea82f6fa3f15b60b4ed9333a5e40c4a7b37580f38086a004ad38b2cbbc9b3913f0e44fbb62162c
|
@@ -36,7 +36,7 @@ module Pandocomatic
|
|
36
36
|
require_relative 'command.rb'
|
37
37
|
|
38
38
|
# Output formats used in pandocomatic
|
39
|
-
OUTPUT_FORMATS = ["docx", "odt", "pdf", "
|
39
|
+
OUTPUT_FORMATS = ["docx", "odt", "pdf", "epub", "epub3", "epub2"]
|
40
40
|
|
41
41
|
# Command to convert a file
|
42
42
|
#
|
@@ -74,7 +74,7 @@ module Pandocomatic
|
|
74
74
|
end
|
75
75
|
|
76
76
|
@metadata = PandocMetadata.load_file @src
|
77
|
-
@dst = @config.
|
77
|
+
@dst = @config.set_destination @dst, @template_name, @metadata
|
78
78
|
|
79
79
|
@errors.push IOError.new(:file_does_not_exist, nil, @src) unless File.exist? @src
|
80
80
|
@errors.push IOError.new(:file_is_not_a_file, nil, @src) unless File.file? @src
|
@@ -134,7 +134,7 @@ module Pandocomatic
|
|
134
134
|
end
|
135
135
|
|
136
136
|
begin
|
137
|
-
unless
|
137
|
+
unless use_output_option @dst then
|
138
138
|
File.open(@dst, 'w') do |file|
|
139
139
|
raise IOError.new(:file_is_not_a_file, nil, @dst) unless File.file? @dst
|
140
140
|
raise IOError.new(:file_is_not_writable, nil, @dst) unless File.writable? @dst
|
@@ -199,14 +199,14 @@ module Pandocomatic
|
|
199
199
|
# Pandoc multi-word options can have the multiple words separated by
|
200
200
|
# both underscore (_) and dash (-).
|
201
201
|
option = option.gsub "-", "_"
|
202
|
-
converter.send option, value unless option == 'output'
|
202
|
+
converter.send option, value unless option == 'output' or option == 'use-extension'
|
203
203
|
# don't let pandoc write the output to enable postprocessing
|
204
204
|
rescue
|
205
205
|
warn "The pandoc option '#{option}' (with value '#{value}') is not recognized by paru. This option is skipped." if debug?
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
|
-
converter.send "output", absolute_dst if
|
209
|
+
converter.send "output", absolute_dst if use_output_option absolute_dst
|
210
210
|
|
211
211
|
begin
|
212
212
|
puts converter.to_command if debug?
|
@@ -267,6 +267,10 @@ module Pandocomatic
|
|
267
267
|
|
268
268
|
private
|
269
269
|
|
270
|
+
def use_output_option(dst)
|
271
|
+
OUTPUT_FORMATS.include?(File.extname(dst).slice(1..-1))
|
272
|
+
end
|
273
|
+
|
270
274
|
# Pandoc version 2 supports multiple pdf engines. Determine which
|
271
275
|
# to use given the options.
|
272
276
|
#
|
@@ -51,8 +51,7 @@ module Pandocomatic
|
|
51
51
|
|
52
52
|
metadata.templates.each do |template_name|
|
53
53
|
raise ConfigurationError.new(:no_such_template, nil, template_name) unless template_name.empty? or config.has_template? template_name
|
54
|
-
|
55
|
-
dst = config.set_extension dst, template_name, metadata
|
54
|
+
|
56
55
|
if not modified_only? or file_modified? @src, dst then
|
57
56
|
subcommand = ConvertFileCommand.new(@config, @src, dst, template_name)
|
58
57
|
push subcommand unless subcommand.nil? or subcommand.skip?
|
@@ -25,17 +25,32 @@ module Pandocomatic
|
|
25
25
|
# default_configuration.yaml.
|
26
26
|
DEFAULT_CONFIG = YAML.load_file File.join(__dir__, 'default_configuration.yaml')
|
27
27
|
|
28
|
-
# Maps pandoc output formats to
|
29
|
-
|
28
|
+
# Maps pandoc output formats to their conventional default extension.
|
29
|
+
DEFAULT_EXTENSION = {
|
30
30
|
'native' => 'hs',
|
31
|
+
'plain' => 'txt',
|
31
32
|
'markdown' => 'md',
|
32
33
|
'markdown_strict' => 'md',
|
33
34
|
'markdown_phpextra' => 'md',
|
34
|
-
'
|
35
|
+
'markdown_mmd' => 'md',
|
36
|
+
'gfm' => 'md',
|
37
|
+
'commonmark' => 'md',
|
38
|
+
'html4' => 'html',
|
35
39
|
'html5' => 'html',
|
36
|
-
'docx' => 'docx',
|
37
40
|
'latex' => 'tex',
|
38
|
-
'
|
41
|
+
'beamer' => 'tex',
|
42
|
+
'context' => 'tex',
|
43
|
+
'docbook4' => 'docbook',
|
44
|
+
'docbook5' => 'docbook',
|
45
|
+
'opendocument' => 'odt',
|
46
|
+
'epub2' => 'epub',
|
47
|
+
'epub3' => 'epub',
|
48
|
+
'asciidoc' => 'adoc',
|
49
|
+
'slidy' => 'html',
|
50
|
+
'slideous' => 'html',
|
51
|
+
'dzslides' => 'html',
|
52
|
+
'revealjs' => 'html',
|
53
|
+
's5' => 'html'
|
39
54
|
}
|
40
55
|
|
41
56
|
# A Configuration object models a pandocomatic configuration.
|
@@ -184,6 +199,57 @@ module Pandocomatic
|
|
184
199
|
File.join dir, "#{basename}.#{find_extension(dst, template_name, metadata)}"
|
185
200
|
end
|
186
201
|
|
202
|
+
# Set the destination file given this Confguration,
|
203
|
+
# template, and metadata
|
204
|
+
#
|
205
|
+
# @param dst [String] path to a destination file
|
206
|
+
# @param template_name [String] the name of the template used to
|
207
|
+
# convert to destination
|
208
|
+
# @param metadata [PandocMetadata] the metadata in the source file
|
209
|
+
def set_destination(dst, template_name, metadata)
|
210
|
+
dir = File.dirname dst
|
211
|
+
|
212
|
+
determine_output_in_pandoc = lambda do |pandoc|
|
213
|
+
if pandoc.has_key? "output"
|
214
|
+
output = pandoc["output"]
|
215
|
+
if output.start_with? "/"
|
216
|
+
# Treat as an absolute path. Note. this probably
|
217
|
+
# does not work on windows?
|
218
|
+
return output
|
219
|
+
else
|
220
|
+
# Put it relative to the current directory
|
221
|
+
return File.join dir, output
|
222
|
+
end
|
223
|
+
end
|
224
|
+
return nil
|
225
|
+
end
|
226
|
+
|
227
|
+
destination = nil
|
228
|
+
|
229
|
+
# Output option in pandoc property has precedence
|
230
|
+
if metadata.has_pandocomatic?
|
231
|
+
pandocomatic = metadata.pandocomatic
|
232
|
+
if pandocomatic.has_key? "pandoc"
|
233
|
+
destination = determine_output_in_pandoc.call pandocomatic["pandoc"]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Output option in template's pandoc property is next
|
238
|
+
if destination.nil? and not template_name.nil? and not template_name.empty? then
|
239
|
+
if @templates[template_name].has_key? "pandoc"
|
240
|
+
destination = determine_output_in_pandoc.call @templates[template_name]["pandoc"]
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
# Else fall back to taking the input file as output file with the
|
245
|
+
# extension updated to the output format
|
246
|
+
if destination.nil?
|
247
|
+
destination = set_extension dst, template_name, metadata
|
248
|
+
end
|
249
|
+
|
250
|
+
destination
|
251
|
+
end
|
252
|
+
|
187
253
|
# Find the extension of the destination file given this Confguration,
|
188
254
|
# template, and metadata
|
189
255
|
#
|
@@ -195,14 +261,29 @@ module Pandocomatic
|
|
195
261
|
# @return [String] the extension to use for the destination file
|
196
262
|
def find_extension(dst, template_name, metadata)
|
197
263
|
extension = "html"
|
264
|
+
|
265
|
+
# Pandoc supports enabling / disabling extensions
|
266
|
+
# using +EXTENSION and -EXTENSION
|
267
|
+
strip_extensions = lambda{|format| format.split(/[+-]/).first}
|
268
|
+
use_extension = lambda do |pandoc|
|
269
|
+
if pandoc.has_key? "use-extension"
|
270
|
+
pandoc["use-extension"]
|
271
|
+
else
|
272
|
+
nil
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
198
276
|
if template_name.nil? or template_name.empty? then
|
199
277
|
if metadata.has_pandocomatic?
|
200
278
|
pandocomatic = metadata.pandocomatic
|
201
279
|
if pandocomatic.has_key? "pandoc"
|
202
280
|
pandoc = pandocomatic["pandoc"]
|
203
|
-
|
204
|
-
|
205
|
-
|
281
|
+
|
282
|
+
ext = use_extension.call pandoc
|
283
|
+
if not ext.nil?
|
284
|
+
extension = ext
|
285
|
+
elsif pandoc.has_key? "to"
|
286
|
+
extension = strip_extensions.call(pandoc["to"])
|
206
287
|
end
|
207
288
|
end
|
208
289
|
end
|
@@ -210,14 +291,17 @@ module Pandocomatic
|
|
210
291
|
# TODO: what if there is no pandoc.to?
|
211
292
|
if @templates[template_name].has_key? "pandoc"
|
212
293
|
pandoc = @templates[template_name]["pandoc"]
|
213
|
-
|
214
|
-
|
294
|
+
ext = use_extension.call pandoc
|
295
|
+
if not ext.nil?
|
296
|
+
extension = nil
|
297
|
+
elsif pandoc.has_key? "to"
|
298
|
+
extension = strip_extensions.call(pandoc["to"])
|
215
299
|
end
|
216
300
|
end
|
217
301
|
end
|
218
302
|
|
219
|
-
extension =
|
220
|
-
|
303
|
+
extension = DEFAULT_EXTENSION[extension] || extension
|
304
|
+
extension
|
221
305
|
end
|
222
306
|
|
223
307
|
# Is there a template with template_name in this Configuration?
|
@@ -50,7 +50,7 @@ module Pandocomatic
|
|
50
50
|
ERROR_STATUS = 1266 # This is the sum of the ascii values of the characters in 'pandocomatic'
|
51
51
|
|
52
52
|
# Pandocomatic's current version
|
53
|
-
VERSION = [0, 2,
|
53
|
+
VERSION = [0, 2, 1]
|
54
54
|
|
55
55
|
# Pandocomatic's default configuration file
|
56
56
|
CONFIG_FILE = 'pandocomatic.yaml'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandocomatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huub de Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paru
|