metanorma 2.1.4 → 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/.rubocop.yml +4 -1
- data/lib/metanorma/collection/collection.rb +10 -4
- data/lib/metanorma/collection/config/config.rb +21 -0
- data/lib/metanorma/collection/config/manifest.rb +4 -1
- data/lib/metanorma/collection/document/document.rb +2 -0
- data/lib/metanorma/collection/filelookup/filelookup.rb +15 -6
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +4 -3
- data/lib/metanorma/collection/manifest/manifest.rb +7 -11
- data/lib/metanorma/collection/renderer/fileparse.rb +12 -39
- data/lib/metanorma/collection/renderer/fileprocess.rb +26 -10
- data/lib/metanorma/collection/renderer/navigation.rb +1 -1
- data/lib/metanorma/collection/renderer/renderer.rb +14 -1
- data/lib/metanorma/collection/renderer/utils.rb +8 -10
- data/lib/metanorma/collection/sectionsplit/collection.rb +1 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +84 -49
- data/lib/metanorma/collection/util/util.rb +24 -11
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +2 -3
- data/lib/metanorma/compile/assets/icc-boilerplate.adoc +41 -0
- data/lib/metanorma/compile/compile.rb +148 -172
- data/lib/metanorma/compile/compile_options.rb +108 -82
- data/lib/metanorma/compile/extract.rb +76 -56
- data/lib/metanorma/compile/flavor.rb +54 -0
- data/lib/metanorma/compile/output_filename.rb +75 -0
- data/lib/metanorma/compile/output_filename_config.rb +27 -0
- data/lib/metanorma/compile/relaton_drop.rb +56 -0
- data/lib/metanorma/compile/render.rb +178 -0
- data/lib/metanorma/compile/validator.rb +26 -0
- data/lib/metanorma/compile/writeable.rb +12 -0
- data/lib/metanorma/input/asciidoc.rb +13 -6
- data/lib/metanorma/registry/registry.rb +11 -8
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +2 -1
- metadata +24 -3
- data/lib/metanorma/compile/compile_validate.rb +0 -68
|
@@ -1,21 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "fileutils"
|
|
2
4
|
require "nokogiri"
|
|
3
5
|
require "htmlentities"
|
|
4
6
|
require "yaml"
|
|
5
7
|
require "fontist"
|
|
6
8
|
require "fontist/manifest/install"
|
|
7
|
-
|
|
9
|
+
require "metanorma-taste"
|
|
10
|
+
require_relative "writeable"
|
|
11
|
+
require_relative "validator"
|
|
8
12
|
require_relative "compile_options"
|
|
9
13
|
require_relative "../util/fontist_helper"
|
|
10
14
|
require_relative "../util/util"
|
|
11
15
|
require_relative "extract"
|
|
12
16
|
require_relative "../collection/sectionsplit/sectionsplit"
|
|
13
17
|
require_relative "../util/worker_pool"
|
|
18
|
+
require_relative "output_filename"
|
|
19
|
+
require_relative "output_filename_config"
|
|
20
|
+
require_relative "flavor"
|
|
21
|
+
require_relative "relaton_drop"
|
|
22
|
+
require_relative "render"
|
|
14
23
|
|
|
15
24
|
module Metanorma
|
|
16
25
|
class Compile
|
|
26
|
+
include Validator
|
|
27
|
+
include CompileOptions
|
|
28
|
+
include Flavor
|
|
29
|
+
include Writeable
|
|
30
|
+
|
|
31
|
+
DEFAULT_NUM_WORKERS = 3
|
|
32
|
+
|
|
17
33
|
# @return [Array<String>]
|
|
18
|
-
attr_reader :errors
|
|
34
|
+
attr_reader :errors
|
|
35
|
+
attr_reader :processor
|
|
19
36
|
|
|
20
37
|
def initialize
|
|
21
38
|
@registry = Metanorma::Registry.instance
|
|
@@ -25,22 +42,48 @@ module Metanorma
|
|
|
25
42
|
@log = Metanorma::Utils::Log.new
|
|
26
43
|
end
|
|
27
44
|
|
|
45
|
+
# Main compile method that orchestrates the document conversion process
|
|
46
|
+
# @param filename [String] path to the input file
|
|
47
|
+
# @param options [Hash] compilation options
|
|
28
48
|
def compile(filename, options = {})
|
|
29
|
-
|
|
49
|
+
process_options!(filename, options)
|
|
30
50
|
@processor = @registry.find_processor(options[:type].to_sym)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
|
|
52
|
+
# Step 1: Generate Semantic XML
|
|
53
|
+
semantic_result = generate_semantic_xml(filename, options)
|
|
54
|
+
return nil unless semantic_result
|
|
55
|
+
|
|
56
|
+
source_file, semantic_xml = semantic_result
|
|
57
|
+
|
|
58
|
+
# Step 2: Prepare output paths
|
|
59
|
+
xml = Nokogiri::XML(semantic_xml, &:huge)
|
|
60
|
+
bibdata = extract_relaton_metadata(xml)
|
|
61
|
+
output_paths = prepare_output_paths(filename, bibdata, options)
|
|
62
|
+
|
|
63
|
+
# Step 3: Determine which output formats to generate
|
|
64
|
+
extensions = get_extensions(options)
|
|
65
|
+
return nil unless extensions
|
|
66
|
+
|
|
67
|
+
# Step 4: Extract information from Semantic XML if requested
|
|
68
|
+
extract_information(semantic_xml, bibdata, options)
|
|
69
|
+
|
|
70
|
+
# Step 5: Generate output formats from Semantic XML
|
|
71
|
+
generate_outputs(
|
|
72
|
+
source_file,
|
|
73
|
+
semantic_xml,
|
|
74
|
+
bibdata,
|
|
75
|
+
extensions,
|
|
76
|
+
output_paths,
|
|
77
|
+
options,
|
|
78
|
+
)
|
|
36
79
|
ensure
|
|
37
80
|
clean_exit(options)
|
|
38
81
|
end
|
|
39
82
|
|
|
40
|
-
def
|
|
83
|
+
def process_options!(filename, options)
|
|
41
84
|
require_libraries(options)
|
|
42
|
-
options =
|
|
43
|
-
validate_options(options)
|
|
85
|
+
options = extract_options(filename, options)
|
|
86
|
+
validate_options!(options)
|
|
44
87
|
@log.save_to(filename, options[:output_dir])
|
|
45
88
|
options[:log] = @log
|
|
46
89
|
end
|
|
@@ -50,7 +93,11 @@ module Metanorma
|
|
|
50
93
|
@log.write
|
|
51
94
|
end
|
|
52
95
|
|
|
53
|
-
|
|
96
|
+
# Step 1: Generate Semantic XML from input file
|
|
97
|
+
# @param filename [String] input file path
|
|
98
|
+
# @param options [Hash] compilation options
|
|
99
|
+
# @return [Array, nil] tuple of [source_file, semantic_xml] or nil on failure
|
|
100
|
+
def generate_semantic_xml(filename, options)
|
|
54
101
|
case extname = File.extname(filename)
|
|
55
102
|
when ".adoc" then process_input_adoc(filename, options)
|
|
56
103
|
when ".xml" then process_input_xml(filename, options)
|
|
@@ -61,184 +108,113 @@ module Metanorma
|
|
|
61
108
|
end
|
|
62
109
|
end
|
|
63
110
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
FileUtils.mkdir_p outfilename
|
|
106
|
-
FileUtils.mv "#{outfilename}.html", outfilename
|
|
107
|
-
FileUtils.mv "#{outfilename}_images", outfilename, force: true
|
|
111
|
+
# Step 2: Prepare output paths for generated files
|
|
112
|
+
# Use default filename template if empty string is provided.
|
|
113
|
+
#
|
|
114
|
+
# @param filename [String] input file path
|
|
115
|
+
# @param bibdata [Nokogiri::XML::Element] the bibliographic data element
|
|
116
|
+
# @param options [Hash] compilation options
|
|
117
|
+
# @return [Hash] paths for different output formats
|
|
118
|
+
def prepare_output_paths(filename, bibdata, options)
|
|
119
|
+
basename = if options[:filename_template].nil?
|
|
120
|
+
filename.sub(/\.[^.]+$/, "")
|
|
121
|
+
else
|
|
122
|
+
drop = RelatonDrop.new(bibdata)
|
|
123
|
+
config = OutputFilenameConfig.new(options[:filename_template])
|
|
124
|
+
config.generate_filename(drop)
|
|
125
|
+
end
|
|
126
|
+
@output_filename = OutputFilename.new(
|
|
127
|
+
basename,
|
|
128
|
+
options[:output_dir],
|
|
129
|
+
@processor,
|
|
130
|
+
)
|
|
131
|
+
{
|
|
132
|
+
xml: @output_filename.semantic_xml,
|
|
133
|
+
orig_filename: filename,
|
|
134
|
+
presentationxml: @output_filename.presentation_xml,
|
|
135
|
+
}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Step 4: Extract information from Semantic XML
|
|
139
|
+
# @param semantic_xml [String] semantic XML content
|
|
140
|
+
# @param options [Hash] compilation options
|
|
141
|
+
def extract_information(semantic_xml, bibdata, options)
|
|
142
|
+
# Extract Relaton bibliographic data
|
|
143
|
+
export_relaton_from_bibdata(bibdata, options) if options[:relaton]
|
|
144
|
+
|
|
145
|
+
# Extract other components (sourcecode, images, requirements)
|
|
146
|
+
if options[:extract]
|
|
147
|
+
Extract.extract(
|
|
148
|
+
semantic_xml,
|
|
149
|
+
options[:extract],
|
|
150
|
+
options[:extract_type],
|
|
151
|
+
)
|
|
108
152
|
end
|
|
109
153
|
end
|
|
110
154
|
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
155
|
+
# Step 5: Generate output formats from Semantic XML
|
|
156
|
+
# @param source_file [String] source file content
|
|
157
|
+
# @param semantic_xml [String] semantic XML content
|
|
158
|
+
# @param bibdata [Nokogiri::XML::Element] the bibliographic data element
|
|
159
|
+
# @param extensions [Array<Symbol>] output formats to generate
|
|
160
|
+
# @param output_paths [Hash] paths for output files
|
|
161
|
+
# @param options [Hash] compilation options
|
|
162
|
+
def generate_outputs(
|
|
163
|
+
source_file, semantic_xml, bibdata, extensions, output_paths, options
|
|
164
|
+
)
|
|
117
165
|
if extensions == %i(presentation)
|
|
118
|
-
|
|
166
|
+
# Just generate presentation XML
|
|
167
|
+
generate_presentation_xml(
|
|
168
|
+
source_file, semantic_xml, bibdata, output_paths, options
|
|
169
|
+
)
|
|
119
170
|
else
|
|
120
|
-
|
|
171
|
+
# Generate multiple output formats with parallel processing
|
|
172
|
+
generate_outputs_parallel(
|
|
173
|
+
source_file, semantic_xml, bibdata, extensions, output_paths, options
|
|
174
|
+
)
|
|
121
175
|
end
|
|
122
176
|
end
|
|
123
177
|
|
|
124
|
-
def
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
178
|
+
def process_input_adoc_hdr(file, options)
|
|
179
|
+
hdr, rest = Metanorma::Input::Asciidoc.new.header(file)
|
|
180
|
+
attrs = hdr.split("\n")
|
|
181
|
+
options[:asciimath] and attrs << ":mn-keep-asciimath:"
|
|
182
|
+
process_input_adoc_overrides(attrs, options)
|
|
183
|
+
"#{attrs.join("\n")}\n\n#{rest}"
|
|
130
184
|
end
|
|
131
185
|
|
|
132
|
-
def
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
186
|
+
def process_input_adoc_overrides(attrs, options)
|
|
187
|
+
@registry.tastes.available_tastes.include?(options[:supplied_type]) or
|
|
188
|
+
return
|
|
189
|
+
c = Metanorma::TasteRegister.get(options[:supplied_type])
|
|
190
|
+
c.process_input_adoc_overrides(attrs, options)
|
|
136
191
|
end
|
|
137
192
|
|
|
138
|
-
def
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def process_ext(ext, file, isodoc, fnames, options)
|
|
146
|
-
fnames[:ext] = @processor.output_formats[ext]
|
|
147
|
-
fnames[:out] = fnames[:f].sub(/\.[^.]+$/, ".#{fnames[:ext]}")
|
|
148
|
-
isodoc_options = get_isodoc_options(file, options, ext)
|
|
149
|
-
thread = true
|
|
150
|
-
unless process_ext_simple(ext, isodoc, fnames, options,
|
|
151
|
-
isodoc_options)
|
|
152
|
-
thread = process_exts1(ext, fnames, isodoc, options, isodoc_options)
|
|
153
|
-
end
|
|
154
|
-
thread
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def process_ext_simple(ext, isodoc, fnames, options, isodoc_options)
|
|
158
|
-
if ext == :rxl
|
|
159
|
-
relaton_export(isodoc, options.merge(relaton: fnames[:out]))
|
|
160
|
-
elsif options[:passthrough_presentation_xml] && ext == :presentation
|
|
161
|
-
#f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
|
|
162
|
-
f = File.exist?(fnames[:orig_filename]) ? fnames[:orig_filename] : fnames[:f]
|
|
163
|
-
FileUtils.cp f, fnames[:presentationxml]
|
|
164
|
-
elsif ext == :html && options[:sectionsplit]
|
|
165
|
-
sectionsplit_convert(fnames[:xml], isodoc, fnames[:out],
|
|
166
|
-
isodoc_options)
|
|
167
|
-
else return false
|
|
168
|
-
end
|
|
169
|
-
true
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def process_exts1(ext, fnames, isodoc, options, isodoc_options)
|
|
173
|
-
if @processor.use_presentation_xml(ext)
|
|
174
|
-
@queue.schedule(ext, fnames.dup, options.dup,
|
|
175
|
-
isodoc_options.dup) do |a, b, c, d|
|
|
176
|
-
process_output_threaded(a, b, c, d)
|
|
177
|
-
end
|
|
178
|
-
else
|
|
179
|
-
process_output_unthreaded(ext, fnames, isodoc, isodoc_options)
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def process_output_threaded(ext, fnames1, options1, isodoc_options1)
|
|
184
|
-
@processor.output(nil, fnames1[:presentationxml], fnames1[:out], ext,
|
|
185
|
-
isodoc_options1)
|
|
186
|
-
wrap_html(options1, fnames1[:ext], fnames1[:out])
|
|
187
|
-
rescue StandardError => e
|
|
188
|
-
strict = ext == :presentation || isodoc_options1[:strict] == true
|
|
189
|
-
isodoc_error_process(e, strict, false)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def process_output_unthreaded(ext, fnames, isodoc, isodoc_options)
|
|
193
|
-
@processor.output(isodoc, fnames[:xml], fnames[:out], ext,
|
|
194
|
-
isodoc_options)
|
|
195
|
-
true # return as Thread
|
|
196
|
-
rescue StandardError => e
|
|
197
|
-
strict = ext == :presentation || isodoc_options[:strict] == "true"
|
|
198
|
-
isodoc_error_process(e, strict, true)
|
|
199
|
-
ext != :presentation
|
|
193
|
+
def process_input_adoc_includes(file, filename)
|
|
194
|
+
dir = File.dirname(filename)
|
|
195
|
+
dir != "." and
|
|
196
|
+
file = file.gsub(/^include::/, "include::#{dir}/")
|
|
197
|
+
.gsub(/^embed::/, "embed::#{dir}/")
|
|
198
|
+
file
|
|
200
199
|
end
|
|
201
200
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
File.open(input_filename, "w:UTF-8") { |f| f.write(file) }
|
|
209
|
-
presxml = File.read(input_filename, encoding: "utf-8")
|
|
210
|
-
_xml, filename, dir = @isodoc.convert_init(presxml, input_filename, false)
|
|
211
|
-
|
|
212
|
-
::Metanorma::Collection::Sectionsplit.new(
|
|
213
|
-
input: input_filename,
|
|
214
|
-
isodoc: @isodoc,
|
|
215
|
-
xml: presxml,
|
|
216
|
-
base: File.basename(output_filename || filename),
|
|
217
|
-
output: output_filename || filename,
|
|
218
|
-
dir: dir,
|
|
219
|
-
compile_opts: opts,
|
|
220
|
-
).build_collection
|
|
201
|
+
def process_input_adoc(filename, options)
|
|
202
|
+
Util.log("[metanorma] Processing: AsciiDoc input.", :info)
|
|
203
|
+
file = read_file(filename)
|
|
204
|
+
file = process_input_adoc_hdr(file, options)
|
|
205
|
+
file = process_input_adoc_includes(file, filename)
|
|
206
|
+
[file, @processor.input_to_isodoc(file, filename, options)]
|
|
221
207
|
end
|
|
222
208
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
else
|
|
229
|
-
puts err.message
|
|
230
|
-
end
|
|
231
|
-
puts err.backtrace.join("\n")
|
|
232
|
-
must_abort and 1
|
|
209
|
+
def process_input_xml(filename, _options)
|
|
210
|
+
Util.log("[metanorma] Processing: Metanorma XML input.", :info)
|
|
211
|
+
# TODO NN: this is a hack -- we should provide/bridge the
|
|
212
|
+
# document attributes in Metanorma XML
|
|
213
|
+
["", read_file(filename)]
|
|
233
214
|
end
|
|
234
215
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def change_output_dir(options)
|
|
238
|
-
if options[:output_dir]
|
|
239
|
-
File.join options[:output_dir], File.basename(options[:filename])
|
|
240
|
-
else options[:filename]
|
|
241
|
-
end
|
|
216
|
+
def read_file(filename)
|
|
217
|
+
File.read(filename, encoding: "utf-8").gsub("\r\n", "\n")
|
|
242
218
|
end
|
|
243
219
|
end
|
|
244
220
|
end
|
|
@@ -2,104 +2,130 @@ require "csv"
|
|
|
2
2
|
|
|
3
3
|
module Metanorma
|
|
4
4
|
class Compile
|
|
5
|
-
|
|
6
|
-
options
|
|
7
|
-
|
|
5
|
+
module CompileOptions
|
|
6
|
+
def require_libraries(options)
|
|
7
|
+
options&.dig(:require)&.each { |r| require r }
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
def extract_xml_options(file)
|
|
11
|
+
xml = Nokogiri::XML(file, &:huge)
|
|
12
|
+
if xml.root
|
|
13
|
+
@registry.root_tags.each do |k, v|
|
|
14
|
+
return { type: k } if v == xml.root.name
|
|
15
|
+
end
|
|
14
16
|
end
|
|
17
|
+
{}
|
|
15
18
|
end
|
|
16
|
-
{}
|
|
17
|
-
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
options[:filename] = filename
|
|
32
|
-
options[:fontlicenseagreement] ||= "no-install-fonts"
|
|
33
|
-
options[:novalid] = o[:novalid] if o[:novalid]
|
|
34
|
-
options
|
|
35
|
-
end
|
|
20
|
+
def extract_options(filename, options)
|
|
21
|
+
o = options_in_file(filename)
|
|
22
|
+
extract_flavor_options(options, o)
|
|
23
|
+
extract_dir_options(options, o, filename)
|
|
24
|
+
options[:extension_keys] ||= o[:extensions]&.split(/, */)&.map(&:to_sym)
|
|
25
|
+
options[:extension_keys] = nil if options[:extension_keys] == [:all]
|
|
26
|
+
options[:format] ||= :asciidoc
|
|
27
|
+
options[:filename] = filename
|
|
28
|
+
options[:fontlicenseagreement] ||= "no-install-fonts"
|
|
29
|
+
options[:novalid] = o[:novalid] if o[:novalid]
|
|
30
|
+
options
|
|
31
|
+
end
|
|
36
32
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
def options_in_file(filename)
|
|
34
|
+
content = read_file(filename)
|
|
35
|
+
Metanorma::Input::Asciidoc.new.extract_metanorma_options(content)
|
|
36
|
+
.merge(extract_xml_options(content))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def extract_flavor_options(options, options_in_file)
|
|
40
|
+
options[:type] ||= options_in_file[:type]
|
|
41
|
+
options[:type] = options[:type]&.to_sym
|
|
42
|
+
options[:supplied_type] = options[:type]
|
|
43
|
+
t = @registry.alias(options[:type]) and options[:type] = t
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def extract_dir_options(options, options_in_file, filename)
|
|
47
|
+
dir = filename.sub(%r(/[^/]+$), "/")
|
|
48
|
+
options_in_file[:relaton] and
|
|
49
|
+
options[:relaton] ||= File.join(dir,
|
|
50
|
+
options_in_file[:relaton])
|
|
51
|
+
options_in_file[:sourcecode] and
|
|
52
|
+
options[:sourcecode] ||= File.join(dir,
|
|
53
|
+
options_in_file[:sourcecode])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def get_extensions(options)
|
|
57
|
+
ext = extract_extensions(options)
|
|
58
|
+
!ext.include?(:presentation) && ext.any? do |e|
|
|
59
|
+
@processor.use_presentation_xml(e)
|
|
60
|
+
end and ext << :presentation
|
|
61
|
+
!ext.include?(:rxl) && options[:site_generate] and
|
|
62
|
+
ext << :rxl
|
|
63
|
+
ext
|
|
64
|
+
end
|
|
46
65
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
def extract_extensions(options)
|
|
67
|
+
options[:extension_keys] ||=
|
|
68
|
+
@processor.output_formats.reduce([]) { |memo, (k, _)| memo << k }
|
|
69
|
+
options[:extension_keys].reduce([]) do |memo, e|
|
|
70
|
+
if @processor.output_formats[e] then memo << e
|
|
71
|
+
else
|
|
72
|
+
unsupported_format_error(e)
|
|
73
|
+
memo
|
|
74
|
+
end
|
|
55
75
|
end
|
|
56
76
|
end
|
|
57
|
-
end
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
def font_install(opt)
|
|
79
|
+
@fontist_installed or
|
|
80
|
+
Util::FontistHelper.install_fonts(@processor, opt)
|
|
81
|
+
@fontist_installed = true
|
|
82
|
+
end
|
|
64
83
|
|
|
65
|
-
|
|
84
|
+
private
|
|
66
85
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
def unsupported_format_error(ext)
|
|
87
|
+
message = "[metanorma] Error: #{ext} format is not supported " \
|
|
88
|
+
"for this standard."
|
|
89
|
+
@errors << message
|
|
90
|
+
Util.log(message, :error)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def get_isodoc_options(file, options, ext)
|
|
94
|
+
ret = @processor.extract_options(file)
|
|
95
|
+
get_isodoc_i18nyaml(options, ret)
|
|
96
|
+
copy_isodoc_options_attrs(options, ret)
|
|
97
|
+
font_manifest_mn2pdf(options, ret, ext)
|
|
98
|
+
ret[:output_formats]&.select! do |k, _|
|
|
99
|
+
options[:extension_keys].include?(k)
|
|
100
|
+
end
|
|
101
|
+
ret[:log] = @log
|
|
102
|
+
ret
|
|
103
|
+
end
|
|
73
104
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
font_manifest_mn2pdf(options, ret, ext)
|
|
80
|
-
ret[:output_formats]&.select! do |k, _|
|
|
81
|
-
options[:extension_keys].include?(k)
|
|
105
|
+
def get_isodoc_i18nyaml(options, ret)
|
|
106
|
+
dir = File.dirname(options[:filename])
|
|
107
|
+
ret[:i18nyaml] or return
|
|
108
|
+
(Pathname.new ret[:i18nyaml]).absolute? or
|
|
109
|
+
ret[:i18nyaml] = File.join(dir, ret[:i18nyaml])
|
|
82
110
|
end
|
|
83
|
-
ret[:log] = @log
|
|
84
|
-
ret
|
|
85
|
-
end
|
|
86
111
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
112
|
+
def copy_isodoc_options_attrs(options, ret)
|
|
113
|
+
ret[:datauriimage] = true if options[:datauriimage]
|
|
114
|
+
ret[:sourcefilename] = options[:filename]
|
|
115
|
+
%i(bare sectionsplit install_fonts baseassetpath aligncrosselements
|
|
116
|
+
tocfigures toctables tocrecommendations strict)
|
|
117
|
+
.each { |x| ret[x] ||= options[x] }
|
|
118
|
+
end
|
|
94
119
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
120
|
+
def font_manifest_mn2pdf(options, ret, ext)
|
|
121
|
+
custom_fonts = Util::FontistHelper
|
|
122
|
+
.has_custom_fonts?(@processor, options, ret)
|
|
98
123
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
ext == :pdf && custom_fonts and
|
|
125
|
+
ret[:mn2pdf] = {
|
|
126
|
+
font_manifest: Util::FontistHelper.location_manifest(@processor, ret),
|
|
127
|
+
}
|
|
128
|
+
end
|
|
103
129
|
end
|
|
104
130
|
end
|
|
105
131
|
end
|