pandocomatic 2.0.1 → 2.2.0
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 +4 -4
- data/lib/pandocomatic/cli.rb +29 -6
- data/lib/pandocomatic/command/convert_dir_command.rb +7 -7
- data/lib/pandocomatic/command/convert_file_command.rb +13 -7
- data/lib/pandocomatic/command/convert_file_multiple_command.rb +28 -19
- data/lib/pandocomatic/configuration.rb +53 -14
- data/lib/pandocomatic/error/cli_error.rb +2 -2
- data/lib/pandocomatic/error/configuration_error.rb +1 -0
- data/lib/pandocomatic/pandoc_metadata.rb +19 -6
- data/lib/pandocomatic/pandocomatic.rb +2 -1
- data/lib/pandocomatic/printer/views/cli_error.txt +2 -0
- data/lib/pandocomatic/printer/views/help.txt +14 -1
- data/lib/pandocomatic/version.rb +2 -2
- metadata +14 -101
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f44c7b8261cd7c59a45102a8fe11a1cbb2202eaed96effff33ced0a4bf50fb8
|
|
4
|
+
data.tar.gz: 437ad6925e13b168a2980fb883574bd68b6cc14c722d8dfcb44fd39b46a42fcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e88c0ae54973b4dbed104edf17936193cfb763ee322ab9afb4bf1596fa7df0d6f7f437e129870f8795ad8855e33b513d432f28185fe071072b287b73a0061db
|
|
7
|
+
data.tar.gz: 45c9438e591086e856d216eeb696e28f7daf7af6fae56dae259610a651cb78c6fefc7d9826f5e00c57da3950a0db20c7067f6e4ac6e1eb88bcad94f49c79188e
|
data/lib/pandocomatic/cli.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2017-
|
|
4
|
+
# Copyright 2017-2025, Huub de Beer <huub@heerdebeer.org>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of pandocomatic.
|
|
7
7
|
#
|
|
@@ -24,6 +24,8 @@ module Pandocomatic
|
|
|
24
24
|
require_relative 'error/cli_error'
|
|
25
25
|
require_relative 'configuration'
|
|
26
26
|
|
|
27
|
+
# rubocop:disable Metrics
|
|
28
|
+
|
|
27
29
|
##
|
|
28
30
|
# Command line options parser for pandocomatic using optimist.
|
|
29
31
|
#
|
|
@@ -49,8 +51,6 @@ module Pandocomatic
|
|
|
49
51
|
end
|
|
50
52
|
end
|
|
51
53
|
|
|
52
|
-
# rubocop:disable Metrics
|
|
53
|
-
|
|
54
54
|
# Parse pandocomatic's global options.
|
|
55
55
|
#
|
|
56
56
|
# @return [Configuration]
|
|
@@ -70,6 +70,7 @@ module Pandocomatic
|
|
|
70
70
|
opt :data_dir, 'Data dir', short: '-d', type: String
|
|
71
71
|
opt :config, 'Configuration file', short: '-c', type: String
|
|
72
72
|
opt :root_path, 'Root path', short: '-r', type: String
|
|
73
|
+
opt :template, 'Template to use for conversion', short: '-t', type: String, multi: true
|
|
73
74
|
|
|
74
75
|
# What to convert and where to put it
|
|
75
76
|
opt :output, 'Output', short: '-o', type: String
|
|
@@ -106,7 +107,7 @@ module Pandocomatic
|
|
|
106
107
|
|
|
107
108
|
# if no input option is specified, all items following the last option
|
|
108
109
|
# are treated as input files.
|
|
109
|
-
if !
|
|
110
|
+
if !options[:input_given]
|
|
110
111
|
Pandocomatic::LOG.debug '✓ Option \'--input\' not used: ' \
|
|
111
112
|
'treat all arguments after last option as input files or directories.'
|
|
112
113
|
options[:input] = args
|
|
@@ -143,12 +144,30 @@ module Pandocomatic
|
|
|
143
144
|
Pandocomatic::LOG.debug '✓ Input files and directories exist.'
|
|
144
145
|
|
|
145
146
|
# You cannot use the --stdout option while converting directories
|
|
146
|
-
if options[:stdout_given]
|
|
147
|
+
if convert_directory?(input) && options[:stdout_given]
|
|
147
148
|
options[:stdout] = false
|
|
148
149
|
raise CLIError, :cannot_use_stdout_with_directory
|
|
149
150
|
end
|
|
150
151
|
Pandocomatic::LOG.debug '✓ Write output to STDOUT.' if options[:stdout_given]
|
|
151
152
|
|
|
153
|
+
# You cannot use the --template option while converting directories
|
|
154
|
+
if convert_directory?(input) && options[:template_given]
|
|
155
|
+
options[:template] = nil
|
|
156
|
+
raise CLIError, :cannot_use_template_with_directory
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Postponing checking for existence of template until configuration
|
|
160
|
+
# hierarchy has been loaded.
|
|
161
|
+
if options[:template_given]
|
|
162
|
+
templates = options[:template]
|
|
163
|
+
duplicates = templates.select { |t| templates.count(t) > 1 }
|
|
164
|
+
|
|
165
|
+
options[:template] = templates.uniq
|
|
166
|
+
|
|
167
|
+
Pandocomatic::LOG.debug "✓ Use templates '#{options[:template]}' for conversion."
|
|
168
|
+
Pandocomatic::LOG.warn " ! Ignoring duplicate templates: #{duplicates}." unless duplicates.empty?
|
|
169
|
+
end
|
|
170
|
+
|
|
152
171
|
if options[:output_given]
|
|
153
172
|
# You cannot use --stdout with --output
|
|
154
173
|
if options[:stdout_given]
|
|
@@ -224,7 +243,7 @@ module Pandocomatic
|
|
|
224
243
|
# rubocop:enable Metrics
|
|
225
244
|
|
|
226
245
|
private_class_method def self.options_need_to_be_validated?(options)
|
|
227
|
-
!
|
|
246
|
+
!options[:version_given] and !options[:help_given]
|
|
228
247
|
end
|
|
229
248
|
|
|
230
249
|
#--
|
|
@@ -267,5 +286,9 @@ module Pandocomatic
|
|
|
267
286
|
raise CLIError.new(:output_is_not_a_file, nil, input) if File.file? input
|
|
268
287
|
raise CLIError.new(:output_is_not_a_directory, nil, input) if File.directory? input
|
|
269
288
|
end
|
|
289
|
+
|
|
290
|
+
private_class_method def self.convert_directory?(input)
|
|
291
|
+
File.directory? input.first
|
|
292
|
+
end
|
|
270
293
|
end
|
|
271
294
|
end
|
|
@@ -72,23 +72,23 @@ module Pandocomatic
|
|
|
72
72
|
Dir.foreach @src_dir do |filename|
|
|
73
73
|
src = File.join @src_dir, filename
|
|
74
74
|
|
|
75
|
-
next if config.skip? src
|
|
75
|
+
next if @config.skip? src
|
|
76
76
|
|
|
77
77
|
@errors.push IOError.new(:file_or_directory_does_not_exist, nil, src) unless File.exist? src
|
|
78
78
|
|
|
79
79
|
dst = File.join @dst_dir, filename
|
|
80
80
|
|
|
81
|
-
if File.symlink?(src) &&
|
|
81
|
+
if File.symlink?(src) && !@config.follow_links?
|
|
82
82
|
subcommand = CreateLinkCommand.new(src, dst)
|
|
83
83
|
elsif File.directory? src
|
|
84
|
-
subcommand = if config.recursive?
|
|
85
|
-
ConvertDirCommand.new(config, src, dst)
|
|
84
|
+
subcommand = if @config.recursive?
|
|
85
|
+
ConvertDirCommand.new(@config, src, dst)
|
|
86
86
|
else
|
|
87
87
|
SkipCommand.new(src, :skipping_directory)
|
|
88
88
|
end
|
|
89
89
|
elsif File.file? src
|
|
90
|
-
if config.convert? src
|
|
91
|
-
subcommand = ConvertFileMultipleCommand.new(config, src, dst)
|
|
90
|
+
if @config.convert? src
|
|
91
|
+
subcommand = ConvertFileMultipleCommand.new(@config, src, dst)
|
|
92
92
|
elsif !modified_only? || file_modified?(src, dst)
|
|
93
93
|
subcommand = CopyFileCommand.new(src, dst)
|
|
94
94
|
end
|
|
@@ -149,7 +149,7 @@ module Pandocomatic
|
|
|
149
149
|
if File.exist? config_file
|
|
150
150
|
current_config.reconfigure config_file
|
|
151
151
|
else
|
|
152
|
-
current_config
|
|
152
|
+
current_config.clone
|
|
153
153
|
end
|
|
154
154
|
end
|
|
155
155
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2017-
|
|
4
|
+
# Copyright 2017-2025, Huub de Beer <Huub@heerdebeer.org>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of pandocomatic.
|
|
7
7
|
#
|
|
@@ -127,10 +127,11 @@ module Pandocomatic
|
|
|
127
127
|
str
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
# Name of the anonymous inner template.
|
|
132
131
|
INTERNAL_TEMPLATE = 'internal template'
|
|
133
132
|
|
|
133
|
+
private
|
|
134
|
+
|
|
134
135
|
def convert_file
|
|
135
136
|
pandoc_options = @metadata.pandoc_options || {}
|
|
136
137
|
template = nil
|
|
@@ -164,11 +165,16 @@ module Pandocomatic
|
|
|
164
165
|
'"--enable pandoc-verbose".'
|
|
165
166
|
end
|
|
166
167
|
|
|
167
|
-
template.
|
|
168
|
+
template_log = Pandocomatic::LOG.indent(YAML.dump(template.to_h).sub('---', ''), 34)
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
if @metadata.pandocomatic?
|
|
171
|
+
template.merge! Template.new(INTERNAL_TEMPLATE, @metadata.pandocomatic)
|
|
172
|
+
|
|
173
|
+
Pandocomatic::LOG.debug ' # Selected template mixed with internal template and pandocomatic metadata ' \
|
|
174
|
+
"gives final template:#{template_log}"
|
|
175
|
+
else
|
|
176
|
+
Pandocomatic::LOG.debug " # Selected template:#{template_log}"
|
|
177
|
+
end
|
|
172
178
|
|
|
173
179
|
# Write out the results of the conversion process to file.
|
|
174
180
|
@dst = @metadata.pandoc_options['output'] if @dst.to_s.empty? && @metadata.pandoc_options.key?('output')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2017—
|
|
4
|
+
# Copyright 2017—2025 Huub de Beer <Huub@heerdebeer.org>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of pandocomatic.
|
|
7
7
|
#
|
|
@@ -49,31 +49,40 @@ module Pandocomatic
|
|
|
49
49
|
@config = config
|
|
50
50
|
@src = src
|
|
51
51
|
|
|
52
|
-
metadata = @config.get_metadata @src
|
|
53
|
-
|
|
54
52
|
subcommands = []
|
|
55
53
|
|
|
56
|
-
if
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
metadata.templates.each do |template_name|
|
|
60
|
-
unless template_name.empty? || config.template?(template_name)
|
|
61
|
-
raise ConfigurationError.new(:no_such_template, nil,
|
|
62
|
-
template_name)
|
|
63
|
-
end
|
|
54
|
+
if @config.use_templates?
|
|
55
|
+
# Command-line specified template overrides all internal templates
|
|
56
|
+
Pandocomatic::LOG.info 'Ignoring any internal pandocomatic configuration from input\'s YAML blocks'
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
@config.selected_templates.each do |template|
|
|
59
|
+
subcommands.push ConvertFileCommand.new(@config, @src, dst, template)
|
|
66
60
|
end
|
|
67
61
|
else
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
metadata = @config.get_metadata @src
|
|
63
|
+
|
|
64
|
+
if metadata&.template?
|
|
65
|
+
# There are templates in this document's metadata, try to use
|
|
66
|
+
# those.
|
|
67
|
+
metadata.templates.each do |template_name|
|
|
68
|
+
unless template_name.empty? || config.template?(template_name)
|
|
69
|
+
raise ConfigurationError.new(:no_such_template, nil,
|
|
70
|
+
template_name)
|
|
71
|
+
end
|
|
70
72
|
|
|
71
|
-
if global_templates.empty?
|
|
72
|
-
subcommands.push ConvertFileCommand.new(@config, @src, dst)
|
|
73
|
-
else
|
|
74
|
-
global_templates.each do |template_name|
|
|
75
73
|
subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name)
|
|
76
74
|
end
|
|
75
|
+
else
|
|
76
|
+
# Try to match any global templates using the glob patterns
|
|
77
|
+
global_templates = @config.determine_templates(@src)
|
|
78
|
+
|
|
79
|
+
if global_templates.empty?
|
|
80
|
+
subcommands.push ConvertFileCommand.new(@config, @src, dst)
|
|
81
|
+
else
|
|
82
|
+
global_templates.each do |template_name|
|
|
83
|
+
subcommands.push ConvertFileCommand.new(@config, @src, dst, template_name)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
77
86
|
end
|
|
78
87
|
end
|
|
79
88
|
|
|
@@ -101,7 +110,7 @@ module Pandocomatic
|
|
|
101
110
|
|
|
102
111
|
description = CommandPrinter.new(self)
|
|
103
112
|
Pandocomatic::LOG.info description
|
|
104
|
-
|
|
113
|
+
|
|
105
114
|
run if !dry_run? && runnable?
|
|
106
115
|
|
|
107
116
|
@subcommands.each(&:execute)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# rubocop:disable Metrics
|
|
4
4
|
#--
|
|
5
|
-
# Copyright 2014—
|
|
5
|
+
# Copyright 2014—2025 Huub de Beer <Huub@heerdebeer.org>
|
|
6
6
|
#
|
|
7
7
|
# This file is part of pandocomatic.
|
|
8
8
|
#
|
|
@@ -109,6 +109,7 @@ module Pandocomatic
|
|
|
109
109
|
'tei' => 'tei',
|
|
110
110
|
'texinfo' => 'texi',
|
|
111
111
|
'textile' => 'textile',
|
|
112
|
+
'typst' => 'typ',
|
|
112
113
|
'xwiki' => 'xwiki',
|
|
113
114
|
'zimwiki' => 'zimwiki'
|
|
114
115
|
}.freeze
|
|
@@ -197,6 +198,15 @@ module Pandocomatic
|
|
|
197
198
|
|
|
198
199
|
load_configuration_hierarchy options, data_dirs
|
|
199
200
|
|
|
201
|
+
# Check if template selected via CLI option exists
|
|
202
|
+
if use_templates?
|
|
203
|
+
non_existing_templates = selected_templates.reject { |t| template? t }
|
|
204
|
+
|
|
205
|
+
unless non_existing_templates.empty?
|
|
206
|
+
raise ConfigurationError.new(:templates_do_not_exist, nil, non_existing_templates)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
200
210
|
@input = if input.nil? || input.empty?
|
|
201
211
|
nil
|
|
202
212
|
elsif input.size > 1
|
|
@@ -255,24 +265,33 @@ module Pandocomatic
|
|
|
255
265
|
def reconfigure(filename)
|
|
256
266
|
settings = PandocomaticYAML.load_file filename
|
|
257
267
|
new_config = Marshal.load(Marshal.dump(self))
|
|
258
|
-
new_config.configure settings, filename
|
|
268
|
+
new_config.configure settings, filename, recursive: true
|
|
259
269
|
new_config
|
|
260
270
|
rescue StandardError => e
|
|
261
271
|
raise ConfigurationError.new(:unable_to_load_config_file, e, filename)
|
|
262
272
|
end
|
|
263
273
|
|
|
274
|
+
# Create a copy of this configuration
|
|
275
|
+
#
|
|
276
|
+
# @return [Configuration] copy
|
|
277
|
+
def clone
|
|
278
|
+
Marshal.load(Marshal.dump(self))
|
|
279
|
+
end
|
|
280
|
+
|
|
264
281
|
# Configure pandocomatic based on a settings Hash
|
|
265
282
|
#
|
|
266
283
|
# @param settings [Hash] a settings Hash to mixin in this
|
|
267
284
|
# @param path [String] the configuration's path or filename
|
|
268
285
|
# Configuration.
|
|
269
|
-
|
|
286
|
+
# @param recursive [Boolean] should this configuration be configured
|
|
287
|
+
# recursively? I.e., when running on a directory?
|
|
288
|
+
def configure(settings, path, recursive: false)
|
|
270
289
|
reset_settings settings['settings'] if settings.key? 'settings'
|
|
271
290
|
|
|
272
291
|
return unless settings.key? 'templates'
|
|
273
292
|
|
|
274
293
|
settings['templates'].each do |name, template|
|
|
275
|
-
reset_template Template.new(name, template, path)
|
|
294
|
+
reset_template Template.new(name, template, path), recursive:
|
|
276
295
|
end
|
|
277
296
|
end
|
|
278
297
|
|
|
@@ -368,6 +387,24 @@ module Pandocomatic
|
|
|
368
387
|
!@options.nil? and @options[:output_given] and @options[:output]
|
|
369
388
|
end
|
|
370
389
|
|
|
390
|
+
# Is the template CLI option given?
|
|
391
|
+
#
|
|
392
|
+
# @return [Boolean]
|
|
393
|
+
def use_templates?
|
|
394
|
+
!@options.nil? and @options[:template_given] and @options[:template] and !@options[:template].empty?
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# Get the selected templates
|
|
398
|
+
#
|
|
399
|
+
# @return [String[]]
|
|
400
|
+
def selected_templates
|
|
401
|
+
if use_templates?
|
|
402
|
+
@options[:template]
|
|
403
|
+
else
|
|
404
|
+
[]
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
|
|
371
408
|
# Get the output file name
|
|
372
409
|
#
|
|
373
410
|
# @return [String]
|
|
@@ -430,8 +467,8 @@ module Pandocomatic
|
|
|
430
467
|
# @param template_name [String] template used; optional parameter
|
|
431
468
|
# @return [PandocMetadata] Pandoc's metadata for given file and template.
|
|
432
469
|
def get_metadata(src, template_name = nil)
|
|
433
|
-
if extract_metadata_from?
|
|
434
|
-
PandocMetadata.load_file src
|
|
470
|
+
if extract_metadata_from?(src)
|
|
471
|
+
PandocMetadata.load_file src, ignore_pandocomatic: use_templates?
|
|
435
472
|
else
|
|
436
473
|
src_format = nil
|
|
437
474
|
|
|
@@ -451,9 +488,9 @@ module Pandocomatic
|
|
|
451
488
|
|
|
452
489
|
if !src_format || src_format == 'markdown'
|
|
453
490
|
# Behave like pandoc: If no source format can be determined, assume markdown
|
|
454
|
-
PandocMetadata.load_file src
|
|
491
|
+
PandocMetadata.load_file src, ignore_pandocomatic: use_templates?
|
|
455
492
|
else
|
|
456
|
-
PandocMetadata.empty src_format
|
|
493
|
+
PandocMetadata.empty src_format, ignore_pandocomatic: use_templates?
|
|
457
494
|
end
|
|
458
495
|
end
|
|
459
496
|
end
|
|
@@ -719,16 +756,18 @@ module Pandocomatic
|
|
|
719
756
|
resolved_template
|
|
720
757
|
end
|
|
721
758
|
|
|
722
|
-
# Reset the template with name in this Configuration based on a new
|
|
759
|
+
# Reset the template with same name in this Configuration based on a new
|
|
723
760
|
# template
|
|
724
761
|
#
|
|
725
762
|
# @param template [Template] the template to use to update the template in
|
|
726
|
-
# this
|
|
727
|
-
|
|
763
|
+
# this Configuration with
|
|
764
|
+
# @param recursive [Boolean] should this configuration be configured
|
|
765
|
+
# recursively? I.e., when running on a directory?
|
|
766
|
+
def reset_template(template, recursive: false)
|
|
728
767
|
name = template.name
|
|
729
768
|
extended_template = extend_template template
|
|
730
769
|
|
|
731
|
-
if @templates.key?
|
|
770
|
+
if recursive && @templates.key?(name)
|
|
732
771
|
@templates[name].merge! extended_template
|
|
733
772
|
else
|
|
734
773
|
@templates[name] = extended_template
|
|
@@ -771,11 +810,11 @@ module Pandocomatic
|
|
|
771
810
|
end
|
|
772
811
|
|
|
773
812
|
def marshal_dump
|
|
774
|
-
[@data_dir, @settings, @templates, @convert_patterns]
|
|
813
|
+
[@data_dir, @settings, @templates, @convert_patterns, @root_path]
|
|
775
814
|
end
|
|
776
815
|
|
|
777
816
|
def marshal_load(array)
|
|
778
|
-
@data_dir, @settings, @templates, @convert_patterns = array
|
|
817
|
+
@data_dir, @settings, @templates, @convert_patterns, @root_path = array
|
|
779
818
|
end
|
|
780
819
|
|
|
781
820
|
def to_stdout?(options)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2017, Huub de Beer <Huub@heerdebeer.org>
|
|
5
|
-
#
|
|
4
|
+
# Copyright 2017-2025, Huub de Beer <Huub@heerdebeer.org>
|
|
6
5
|
# This file is part of pandocomatic.
|
|
7
6
|
#
|
|
8
7
|
# Pandocomatic is free software: you can redistribute it and/or modify
|
|
@@ -40,6 +39,7 @@ module Pandocomatic
|
|
|
40
39
|
# :output_it_not_writable,
|
|
41
40
|
|
|
42
41
|
# :cannot_use_stdout_with_directory
|
|
42
|
+
# :cannot_use_template_with_directory
|
|
43
43
|
# :cannot_use_both_output_and_stdout
|
|
44
44
|
|
|
45
45
|
# :unknown_option,
|
|
@@ -49,10 +49,14 @@ module Pandocomatic
|
|
|
49
49
|
# Create an empty metadata object with only the source format set.
|
|
50
50
|
#
|
|
51
51
|
# @param src_format [String] the source format
|
|
52
|
+
# @param ignore_pandocomatic [Boolean] when true, ignore pandocomatic
|
|
53
|
+
# configuration in YAML metadata blocks
|
|
52
54
|
# @return [PandocMetadata[ empty metadata with only pandoc's source format
|
|
53
55
|
# set.
|
|
54
|
-
def self.empty(src_format)
|
|
55
|
-
PandocMetadata.new
|
|
56
|
+
def self.empty(src_format, ignore_pandocomatic: false)
|
|
57
|
+
metadata = PandocMetadata.new
|
|
58
|
+
metadata['pandocomatic_'] = { 'pandoc' => { 'from' => src_format } } unless ignore_pandocomatic
|
|
59
|
+
metadata
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
# Collect the metadata embedded in the src file and create a new
|
|
@@ -61,8 +65,8 @@ module Pandocomatic
|
|
|
61
65
|
# @param src [String] the path to the file to load metadata from
|
|
62
66
|
# @return [PandocMetadata] the metadata in the source file, or an empty
|
|
63
67
|
# one if no such metadata is contained in the source file.
|
|
64
|
-
def self.load_file(src)
|
|
65
|
-
self.load File.read(src), src
|
|
68
|
+
def self.load_file(src, ignore_pandocomatic: false)
|
|
69
|
+
self.load File.read(src), path: src, ignore_pandocomatic:
|
|
66
70
|
end
|
|
67
71
|
|
|
68
72
|
# Collect the metadata embedded in the src file and create a new
|
|
@@ -70,18 +74,27 @@ module Pandocomatic
|
|
|
70
74
|
#
|
|
71
75
|
# @param input [String] the string to load the metadata from
|
|
72
76
|
# @param path [String|Nil] the path to the source of the input, if any
|
|
77
|
+
# @param ignore_pandocomatic [Boolean] when true, ignore pandocomatic
|
|
78
|
+
# configuration in YAML metadata blocks
|
|
73
79
|
# @return [PandocMetadata] the metadata in the source file, or an empty
|
|
74
80
|
# one if no such metadata is contained in the source file.
|
|
75
81
|
#
|
|
76
82
|
# @raise [PandocomaticError] when the pandoc metadata cannot be
|
|
77
83
|
# extracted.
|
|
78
|
-
def self.load(input, path
|
|
84
|
+
def self.load(input, path: nil, ignore_pandocomatic: false)
|
|
79
85
|
yaml, pandocomatic_blocks = extract_metadata(input, path)
|
|
80
86
|
|
|
81
87
|
if yaml.empty?
|
|
82
88
|
PandocMetadata.new
|
|
83
89
|
else
|
|
84
|
-
PandocMetadata.new PandocomaticYAML.load(yaml, path), unique: pandocomatic_blocks <= 1
|
|
90
|
+
metadata = PandocMetadata.new PandocomaticYAML.load(yaml, path), unique: pandocomatic_blocks <= 1
|
|
91
|
+
|
|
92
|
+
if ignore_pandocomatic
|
|
93
|
+
metadata.delete('pandocomatic')
|
|
94
|
+
metadata.delete('pandocomatic_')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
metadata
|
|
85
98
|
end
|
|
86
99
|
end
|
|
87
100
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2014—
|
|
4
|
+
# Copyright 2014—2025, Huub de Beer <huub@heerdebeer.org>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of pandocomatic.
|
|
7
7
|
#
|
|
@@ -219,6 +219,7 @@ module Pandocomatic
|
|
|
219
219
|
# An unexpected error has occurred; break off the program drastically
|
|
220
220
|
# for now. This is likely a bug: ask the user to report it.
|
|
221
221
|
UnknownErrorPrinter.new(e).print
|
|
222
|
+
LOG.error e.backtrace.join("\n")
|
|
222
223
|
exit ERROR_STATUS + 2
|
|
223
224
|
ensure
|
|
224
225
|
configuration&.clean_up!
|
|
@@ -14,6 +14,8 @@ See `pandocomatic --help` which options are allowed.
|
|
|
14
14
|
<%=@error.error.message%>.
|
|
15
15
|
<% when :cannot_use_stdout_with_directory %>
|
|
16
16
|
Using `--stdout/-s` with an input directory is not allowed.
|
|
17
|
+
<% when :cannot_use_template_with_directory %>
|
|
18
|
+
Using `--template/-t` with an input directory is not allowed.
|
|
17
19
|
<% when :cannot_use_both_output_and_stdout %>
|
|
18
20
|
Using both `--output/-o` and `--stdout/-s` is not allowed.
|
|
19
21
|
Use eiter a specific output file or directory, or standard out, not both.
|
|
@@ -97,6 +97,19 @@ OPTIONS
|
|
|
97
97
|
respectively. In a file, the property 'use-template' tells
|
|
98
98
|
pandocomatic which template to use.
|
|
99
99
|
|
|
100
|
+
-t TEMPLATE, --template TEMPLATE
|
|
101
|
+
Use given TEMPLATE for conversion. TEMPLATE should be
|
|
102
|
+
defined in pandocomatic's configuration hierarchy. TEMPLATE
|
|
103
|
+
will override any internal template. More so pandocomatic
|
|
104
|
+
configuration in YAML block will be ignored.
|
|
105
|
+
|
|
106
|
+
Only allowed when converting files; option not allowed when
|
|
107
|
+
converting directories.
|
|
108
|
+
|
|
109
|
+
You can use this option multiple times. For each given
|
|
110
|
+
TEMPLATE a separate conversion is run. Duplicate TEMPLATEs
|
|
111
|
+
are ignored.
|
|
112
|
+
|
|
100
113
|
-m, --modified-only
|
|
101
114
|
|
|
102
115
|
Only convert files that have been modified. Only source files
|
|
@@ -179,7 +192,7 @@ AUTHOR
|
|
|
179
192
|
|
|
180
193
|
LICENSE
|
|
181
194
|
|
|
182
|
-
Copyright 2014—
|
|
195
|
+
Copyright 2014—2025 Huub de Beer <huub@heerdebeer.org>
|
|
183
196
|
|
|
184
197
|
Pandocomatic is free software: you can redistribute it and/or modify
|
|
185
198
|
it under the terms of the GNU General Public License as published by the
|
data/lib/pandocomatic/version.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
#--
|
|
4
|
-
# Copyright 2023—
|
|
4
|
+
# Copyright 2023—2025 Huub de Beer <Huub@heerdebeer.org>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of pandocomatic.
|
|
7
7
|
#
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
#++
|
|
21
21
|
module Pandocomatic
|
|
22
22
|
# Pandocomatic's current version.
|
|
23
|
-
VERSION = [2,
|
|
23
|
+
VERSION = [2, 2, 0].freeze
|
|
24
24
|
end
|
metadata
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pandocomatic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Huub de Beer
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: logger
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '1.7'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '1.7'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: optimist
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '3.
|
|
32
|
+
version: '3.2'
|
|
34
33
|
- - ">="
|
|
35
34
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: '3.
|
|
35
|
+
version: '3.2'
|
|
37
36
|
type: :runtime
|
|
38
37
|
prerelease: false
|
|
39
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
39
|
requirements:
|
|
41
40
|
- - "~>"
|
|
42
41
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: '3.
|
|
42
|
+
version: '3.2'
|
|
44
43
|
- - ">="
|
|
45
44
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '3.
|
|
45
|
+
version: '3.2'
|
|
47
46
|
- !ruby/object:Gem::Dependency
|
|
48
47
|
name: paru
|
|
49
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,7 +52,7 @@ dependencies:
|
|
|
53
52
|
version: '1.1'
|
|
54
53
|
- - ">="
|
|
55
54
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: 1.
|
|
55
|
+
version: 1.5.2
|
|
57
56
|
type: :runtime
|
|
58
57
|
prerelease: false
|
|
59
58
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -63,91 +62,7 @@ dependencies:
|
|
|
63
62
|
version: '1.1'
|
|
64
63
|
- - ">="
|
|
65
64
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: 1.
|
|
67
|
-
- !ruby/object:Gem::Dependency
|
|
68
|
-
name: minitest
|
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
|
70
|
-
requirements:
|
|
71
|
-
- - "~>"
|
|
72
|
-
- !ruby/object:Gem::Version
|
|
73
|
-
version: 5.25.1
|
|
74
|
-
type: :development
|
|
75
|
-
prerelease: false
|
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
77
|
-
requirements:
|
|
78
|
-
- - "~>"
|
|
79
|
-
- !ruby/object:Gem::Version
|
|
80
|
-
version: 5.25.1
|
|
81
|
-
- !ruby/object:Gem::Dependency
|
|
82
|
-
name: minitest-reporters
|
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
|
84
|
-
requirements:
|
|
85
|
-
- - "~>"
|
|
86
|
-
- !ruby/object:Gem::Version
|
|
87
|
-
version: 1.7.1
|
|
88
|
-
type: :development
|
|
89
|
-
prerelease: false
|
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
-
requirements:
|
|
92
|
-
- - "~>"
|
|
93
|
-
- !ruby/object:Gem::Version
|
|
94
|
-
version: 1.7.1
|
|
95
|
-
- !ruby/object:Gem::Dependency
|
|
96
|
-
name: rake
|
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
|
98
|
-
requirements:
|
|
99
|
-
- - "~>"
|
|
100
|
-
- !ruby/object:Gem::Version
|
|
101
|
-
version: 13.2.1
|
|
102
|
-
type: :development
|
|
103
|
-
prerelease: false
|
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
-
requirements:
|
|
106
|
-
- - "~>"
|
|
107
|
-
- !ruby/object:Gem::Version
|
|
108
|
-
version: 13.2.1
|
|
109
|
-
- !ruby/object:Gem::Dependency
|
|
110
|
-
name: rubocop
|
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
|
112
|
-
requirements:
|
|
113
|
-
- - "~>"
|
|
114
|
-
- !ruby/object:Gem::Version
|
|
115
|
-
version: 1.66.1
|
|
116
|
-
type: :development
|
|
117
|
-
prerelease: false
|
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
119
|
-
requirements:
|
|
120
|
-
- - "~>"
|
|
121
|
-
- !ruby/object:Gem::Version
|
|
122
|
-
version: 1.66.1
|
|
123
|
-
- !ruby/object:Gem::Dependency
|
|
124
|
-
name: yard
|
|
125
|
-
requirement: !ruby/object:Gem::Requirement
|
|
126
|
-
requirements:
|
|
127
|
-
- - "~>"
|
|
128
|
-
- !ruby/object:Gem::Version
|
|
129
|
-
version: 0.9.37
|
|
130
|
-
type: :development
|
|
131
|
-
prerelease: false
|
|
132
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
133
|
-
requirements:
|
|
134
|
-
- - "~>"
|
|
135
|
-
- !ruby/object:Gem::Version
|
|
136
|
-
version: 0.9.37
|
|
137
|
-
- !ruby/object:Gem::Dependency
|
|
138
|
-
name: rdoc
|
|
139
|
-
requirement: !ruby/object:Gem::Requirement
|
|
140
|
-
requirements:
|
|
141
|
-
- - ">="
|
|
142
|
-
- !ruby/object:Gem::Version
|
|
143
|
-
version: '0'
|
|
144
|
-
type: :development
|
|
145
|
-
prerelease: false
|
|
146
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
147
|
-
requirements:
|
|
148
|
-
- - ">="
|
|
149
|
-
- !ruby/object:Gem::Version
|
|
150
|
-
version: '0'
|
|
65
|
+
version: 1.5.2
|
|
151
66
|
description: Pandocomatic is a tool to automate using pandoc. With pandocomatic you
|
|
152
67
|
can express common patterns of using pandoc for generating your documents. Applied
|
|
153
68
|
to a directory, pandocomatic can act as a static site generator.
|
|
@@ -217,10 +132,9 @@ files:
|
|
|
217
132
|
- lib/pandocomatic/warning.rb
|
|
218
133
|
homepage: https://heerdebeer.org/Software/markdown/pandocomatic/
|
|
219
134
|
licenses:
|
|
220
|
-
- GPL-3.0
|
|
135
|
+
- GPL-3.0-or-later
|
|
221
136
|
metadata:
|
|
222
137
|
rubygems_mfa_required: 'true'
|
|
223
|
-
post_install_message:
|
|
224
138
|
rdoc_options: []
|
|
225
139
|
require_paths:
|
|
226
140
|
- lib
|
|
@@ -236,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
236
150
|
version: '0'
|
|
237
151
|
requirements:
|
|
238
152
|
- pandoc, a universal document converter
|
|
239
|
-
rubygems_version: 3.
|
|
240
|
-
signing_key:
|
|
153
|
+
rubygems_version: 3.6.9
|
|
241
154
|
specification_version: 4
|
|
242
155
|
summary: Automate the use of pandoc
|
|
243
156
|
test_files: []
|