metanorma 1.3.1 → 1.3.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.
@@ -15,27 +15,71 @@ module Metanorma
15
15
  def read_files(path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
16
16
  files = {}
17
17
  @xml.xpath(ns("//docref")).each do |d|
18
- identifier = d.at(ns("./identifier")).text
19
- files[identifier] = file_entry(d, path)
20
- next if files[identifier][:attachment]
18
+ identifier = d.at(ns("./identifier")).children.to_xml
19
+ files[identifier] = file_entry(d, identifier, path)
20
+ if files[identifier][:attachment]
21
+ files[identifier][:bibdata] = Metanorma::Document
22
+ .attachment_bibitem(identifier).root
23
+ else
24
+ file, _filename = targetfile(files[identifier], read: true)
25
+ xml = Nokogiri::XML(file)
26
+ add_document_suffix(identifier, xml)
27
+ files[identifier][:anchors] = read_anchors(xml)
28
+ files[identifier][:bibdata] = xml.at(ns("//bibdata"))
29
+ end
30
+ files[identifier][:bibitem] = files[identifier][:bibdata].dup
31
+ files[identifier][:bibitem].name = "bibitem"
32
+ files[identifier][:bibitem]["hidden"] = "true"
33
+ files[identifier][:bibitem]&.at("./*[local-name() = 'ext']")&.remove
34
+ end
35
+ add_section_split(files)
36
+ end
21
37
 
22
- file, _filename = targetfile(files[identifier], true)
23
- xml = Nokogiri::XML(file)
24
- add_document_suffix(identifier, xml)
25
- files[identifier][:anchors] = read_anchors(xml)
26
- files[identifier][:bibdata] = xml.at(ns("//bibdata"))
38
+ def add_section_split(files)
39
+ files.keys.each_with_object({}) do |k, m|
40
+ if files[k][:sectionsplit] == "true" && !files[k]["attachment"]
41
+ sectionsplit(files[k][:rel_path]).each_with_index do |f1, i|
42
+ m[k + f1[:title]] =
43
+ { parentid: k, presentationxml: true, type: "fileref",
44
+ rel_path: f1[:url], out_path: File.basename(f1[:url]),
45
+ anchors: read_anchors(Nokogiri::XML(File.read(f1[:url]))),
46
+ bibdata: files[k][:bibdata], ref: f1[:url] }
47
+ m[k + f1[:title]][:bare] = true unless i.zero?
48
+ end
49
+ m[k] = files[k]
50
+ else
51
+ m[k] = files[k]
52
+ end
27
53
  end
28
- files
29
54
  end
30
55
 
31
- def file_entry(docref, path)
32
- ret = if docref["fileref"]
33
- { type: "fileref", ref: File.join(path, docref["fileref"]),
34
- rel_path: docref["fileref"] }
56
+ def sectionsplit(file)
57
+ Compile.new.compile(
58
+ file, { format: :asciidoc, extension_keys: [:presentation] }
59
+ .merge(@compile_options)
60
+ )
61
+ r = file.sub(/\.xml$/, ".presentation.xml")
62
+ @isodoc.sectionsplit(
63
+ Nokogiri::XML(File.read(r)), File.basename(r), File.dirname(r)
64
+ ).sort_by { |f| f[:order] }
65
+ end
66
+
67
+ # rel_path is the source file address, determined relative to the YAML.
68
+ # out_path is the destination file address, with any references outside
69
+ # the working directory (../../...) truncated
70
+ def file_entry(ref, identifier, _path)
71
+ out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
72
+ ret = if ref["fileref"]
73
+ { type: "fileref", ref: @documents[identifier].file,
74
+ rel_path: ref["fileref"],
75
+ out_path: out }
35
76
  else
36
- { type: "id", ref: docref["id"] }
77
+ { type: "id", ref: ref["id"] }
37
78
  end
38
- ret[:attachment] = docref["attachment"] if docref["attachment"]
79
+ ret[:attachment] = ref["attachment"] if ref["attachment"]
80
+ ret[:sectionsplit] = ref["sectionsplit"] if ref["sectionsplit"]
81
+ ret[:presentationxml] = ref["presentation-xml"] if ref["presentation-xml"]
82
+ ret[:bareafterfirst] = ref["bare-after-first"] if ref["bare-after-first"]
39
83
  ret
40
84
  end
41
85
 
@@ -58,12 +102,20 @@ module Metanorma
58
102
 
59
103
  # return file contents + output filename for each file in the collection,
60
104
  # given a docref entry
61
- # @param data [Hash]
62
- # @param read [Boolean]
105
+ # @param data [Hash] docref entry
106
+ # @param read [Boolean] read the file in and return it
107
+ # @param doc [Boolean] I am a Metanorma document,
108
+ # so my URL should end with html or pdf or whatever
109
+ # @param relative [Boolean] Return output path,
110
+ # formed relative to YAML file, not input path, relative to calling function
63
111
  # @return [Array<String, nil>]
64
- def targetfile(data, read = false, doc = true)
65
- if data[:type] == "fileref" then ref_file data[:ref], read, doc
66
- else xml_file data[:id], read
112
+ def targetfile(data, options)
113
+ options = { read: false, doc: true, relative: false }.merge(options)
114
+ path = options[:relative] ? data[:rel_path] : data[:ref]
115
+ if data[:type] == "fileref"
116
+ ref_file path, data[:out_path], options[:read], options[:doc]
117
+ else
118
+ xml_file data[:id], options[:read]
67
119
  end
68
120
  end
69
121
 
@@ -71,43 +123,74 @@ module Metanorma
71
123
  # @param read [Boolean]
72
124
  # @param doc [Boolean]
73
125
  # @return [Array<String, nil>]
74
- def ref_file(ref, read, doc)
126
+ def ref_file(ref, out, read, doc)
75
127
  file = File.read(ref, encoding: "utf-8") if read
76
- filename = ref.dup
128
+ filename = out.dup
77
129
  filename.sub!(/\.xml$/, ".html") if doc
78
130
  [file, filename]
79
131
  end
80
132
 
81
133
  # compile and output individual file in collection
82
- def file_compile(f, filename, identifier)
83
- # warn "metanorma compile -x html #{f.path}"
134
+ # warn "metanorma compile -x html #{f.path}"
135
+ def file_compile(file, filename, identifier)
84
136
  c = Compile.new
85
- c.compile f.path, { format: :asciidoc,
86
- extension_keys: @format }.merge(@compile_options)
137
+ c.compile file.path, { format: :asciidoc, extension_keys: @format }
138
+ .merge(compile_options(identifier))
87
139
  @files[identifier][:outputs] = {}
140
+ file_compile_formats(file, filename, identifier, c)
141
+ end
142
+
143
+ def compile_options(identifier)
144
+ ret = @compile_options.dup
145
+ Array(@directives).include?("presentation-xml") ||
146
+ @files[identifier][:presentationxml] and
147
+ ret.merge!(passthrough_presentation_xml: true)
148
+ @files[identifier][:sectionsplit] == "true" and
149
+ ret.merge!(sectionsplit: "true")
150
+ @files[identifier][:bare] == true and
151
+ ret.merge!(bare: true)
152
+ ret
153
+ end
154
+
155
+ def file_compile_formats(file, filename, identifier, compile)
88
156
  @format.each do |e|
89
- ext = c.processor.output_formats[e]
90
- fn = File.basename(filename).sub(/(?<=\.)[^\.]+$/, ext.to_s)
91
- FileUtils.mv f.path.sub(/\.xml$/, ".#{ext}"), File.join(@outdir, fn)
92
- @files[identifier][:outputs][e] = File.join(@outdir, fn)
157
+ ext = compile.processor.output_formats[e]
158
+ fn = File.basename(filename).sub(/(?<=\.)[^.]+$/, ext.to_s)
159
+ if /html$/.match?(ext) && @files[identifier][:sectionsplit]
160
+ # file_sectionsplit_copy(file, fn, identifier, ext, e)
161
+ else
162
+ FileUtils.cp file.path.sub(/\.xml$/, ".#{ext}"),
163
+ File.join(@outdir, fn)
164
+ @files[identifier][:outputs][e] = File.join(@outdir, fn)
165
+ end
93
166
  end
94
167
  end
95
168
 
169
+ def file_sectionsplit_copy(file, base, identifier, ext, format)
170
+ dir = file.path.sub(/\.xml$/, ".#{ext}_collection")
171
+ files = Dir.glob("#{dir}/*.#{ext}")
172
+ FileUtils.cp files, @outdir
173
+ cover = File.join(@outdir, base.sub(/\.html$/, ".index.html"))
174
+ FileUtils.cp File.join(dir, "index.html"), cover
175
+ @files[identifier][:outputs][format] = cover
176
+ end
177
+
96
178
  def copy_file_to_dest(fileref)
97
- _file, filename = targetfile(fileref, true, false)
98
- dest = File.join(@outdir, fileref[:rel_path])
179
+ dest = File.join(@outdir, fileref[:out_path])
99
180
  FileUtils.mkdir_p(File.dirname(dest))
100
- FileUtils.cp filename, dest
181
+ FileUtils.cp fileref[:ref], dest
101
182
  end
102
183
 
103
184
  # process each file in the collection
104
185
  # files are held in memory, and altered as postprocessing
105
186
  def files # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
106
187
  internal_refs = locate_internal_refs
107
- @files.each do |identifier, x|
188
+ @files.each_with_index do |(identifier, x), i|
189
+ i.positive? && Array(@directives).include?("bare-after-first") and
190
+ @compile_options.merge!(bare: true)
108
191
  if x[:attachment] then copy_file_to_dest(x)
109
192
  else
110
- file, filename = targetfile(x, true)
193
+ file, filename = targetfile(x, read: true)
111
194
  file = update_xrefs(file, identifier, internal_refs)
112
195
  Tempfile.open(["collection", ".xml"], encoding: "utf-8") do |f|
113
196
  f.write(file)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "util"
4
+
3
5
  module Metanorma
4
6
  # Metanorma collection's manifest
5
7
  class CollectionManifest
@@ -15,6 +17,7 @@ module Metanorma
15
17
  @title = title
16
18
  @docref = docref
17
19
  @manifest = manifest
20
+ @disambig = Util::DisambigFiles.new
18
21
  end
19
22
 
20
23
  class << self
@@ -43,9 +46,11 @@ module Metanorma
43
46
  # @return [Hash{String=>String}]
44
47
  def parse_docref(mnf)
45
48
  mnf.xpath("xmlns:docref").map do |dr|
46
- h = { "identifier" => dr.at("identifier").text }
47
- h["fileref"] = dr[:fileref] if dr[:fileref]
49
+ h = { "identifier" => dr.at("identifier").children.to_xml }
50
+ dr[:fileref] and h["fileref"] = dr[:fileref]
48
51
  h["attachment"] = dr[:attachment] if dr[:attachment]
52
+ h["sectionsplit"] = dr[:sectionsplit] if dr[:sectionsplit]
53
+ h["presentation-xml"] = dr[:presentationxml] if dr[:presentationxml]
49
54
  h
50
55
  end
51
56
  end
@@ -57,18 +62,19 @@ module Metanorma
57
62
  @manifest.each { |mnf| mnf.collection = col }
58
63
  end
59
64
 
60
- # @param dir [String] path to coolection
65
+ # @param dir [String] path to collection
61
66
  # @return [Hash<String, Metanorma::Document>]
62
67
  def documents(dir = "")
63
68
  docs = @docref.each_with_object({}) do |dr, m|
64
69
  next m unless dr["fileref"]
65
70
 
66
- m[dr["identifier"]] = Document.parse_file(File.join(dir, dr["fileref"]), dr["attachment"])
71
+ m[dr["identifier"]] = Document.parse_file(
72
+ File.join(dir, dr["fileref"]),
73
+ dr["attachment"], dr["identifier"]
74
+ )
67
75
  m
68
76
  end
69
- @manifest.reduce(docs) do |mem, mnf|
70
- mem.merge mnf.documents(dir)
71
- end
77
+ @manifest.reduce(docs) { |mem, mnf| mem.merge mnf.documents(dir) }
72
78
  end
73
79
 
74
80
  # @param builder [Nokogiri::XML::Builder]
@@ -99,14 +105,28 @@ module Metanorma
99
105
 
100
106
  # @param builder [Nokogiri::XML::Builder]
101
107
  def docref_to_xml(builder)
108
+ @disambig = Util::DisambigFiles.new
102
109
  @docref.each do |dr|
103
- drf = builder.docref { |b| b.identifier dr["identifier"] }
104
- drf[:fileref] = dr["fileref"]
105
- drf[:attachment] = dr["attachment"] if dr["attachment"]
106
- if collection.directives.include?("documents-inline")
107
- id = collection.documents.find_index { |k, _| k == dr["identifier"] }
108
- drf[:id] = format("doc%<index>09d", index: id)
110
+ drf = builder.docref do |b|
111
+ b.identifier do |i|
112
+ i << dr["identifier"]
113
+ end
114
+ end
115
+ docref_to_xml_attrs(drf, dr)
116
+ end
117
+ end
118
+
119
+ def docref_to_xml_attrs(elem, docref)
120
+ elem[:fileref] = @disambig.source2dest_filename(docref["fileref"])
121
+ elem[:attachment] = docref["attachment"] if docref["attachment"]
122
+ elem[:sectionsplit] = docref["sectionsplit"] if docref["sectionsplit"]
123
+ elem[:presentationxml] = "true" if docref["presentation-xml"] &&
124
+ docref["presentation-xml"] == "true" || docref["presentation-xml"] == true
125
+ if collection.directives.include?("documents-inline")
126
+ id = collection.documents.find_index do |k, _|
127
+ k == docref["identifier"]
109
128
  end
129
+ elem[:id] = format("doc%<index>09d", index: id)
110
130
  end
111
131
  end
112
132
  end
@@ -3,6 +3,7 @@
3
3
  require "isodoc"
4
4
  require_relative "collection_fileprocess"
5
5
  require_relative "fontist_utils"
6
+ require_relative "util"
6
7
 
7
8
  module Metanorma
8
9
  # XML collection renderer
@@ -21,9 +22,9 @@ module Metanorma
21
22
  # the collection, and that the flavour gem can sensibly process it. We may
22
23
  # need to enhance metadata in the flavour gems isodoc/metadata.rb with
23
24
  # collection metadata
24
- def initialize(xml, folder, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
25
+ def initialize(collection, folder, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
25
26
  check_options options
26
- @xml = Nokogiri::XML xml # @xml is the collection manifest
27
+ @xml = Nokogiri::XML collection.to_xml # @xml is the collection manifest
27
28
  @lang = @xml&.at(ns("//bibdata/language"))&.text || "en"
28
29
  @script = @xml&.at(ns("//bibdata/script"))&.text || "Latn"
29
30
  @doctype = doctype
@@ -34,12 +35,16 @@ module Metanorma
34
35
 
35
36
  @outdir = options[:output_folder]
36
37
  @coverpage = options[:coverpage]
37
- @format = options[:format]
38
+ @format = Util.sort_extensions_execution(options[:format])
38
39
  @compile_options = options[:compile] || {}
39
40
  @log = options[:log]
41
+ @documents = collection.documents
42
+ @directives = collection.directives
43
+ @disambig = Util::DisambigFiles.new
40
44
 
41
45
  # list of files in the collection
42
46
  @files = read_files folder
47
+ isodoc_populate(@isodoc)
43
48
  FileUtils.rm_rf @outdir
44
49
  FileUtils.mkdir_p @outdir
45
50
  end
@@ -51,7 +56,7 @@ module Metanorma
51
56
  # @option options [Strong] :ourput_folder output directory
52
57
  def self.render(col, options = {})
53
58
  folder = File.dirname col.file
54
- cr = new(col.to_xml, folder, options)
59
+ cr = new(col, folder, options)
55
60
  cr.files
56
61
  cr.concatenate(col, options)
57
62
  cr.coverpage if options[:format]&.include?(:html)
@@ -61,11 +66,13 @@ module Metanorma
61
66
  options[:format] << :presentation if options[:format].include?(:pdf)
62
67
  options[:format].uniq.each do |e|
63
68
  next unless %i(presentation xml).include?(e)
69
+
64
70
  ext = e == :presentation ? "presentation.xml" : e.to_s
65
71
  out = col.clone
66
72
  out.directives << "documents-inline"
67
- out.documents.keys.each do |id|
73
+ out.documents.each_key do |id|
68
74
  next if @files[id][:attachment]
75
+
69
76
  filename = @files[id][:outputs][e]
70
77
  out.documents[id] = Metanorma::Document.raw_file(filename)
71
78
  end
@@ -100,15 +107,21 @@ module Metanorma
100
107
  end
101
108
 
102
109
  # The isodoc class for the metanorma flavour we are using
103
- def isodoc # rubocop:disable Metrics/MethodLength
110
+ def isodoc
104
111
  x = Asciidoctor.load nil, backend: @doctype.to_sym
105
112
  isodoc = x.converter.html_converter(Dummy.new)
106
113
  isodoc.i18n_init(@lang, @script) # read in internationalisation
114
+ isodoc.metadata_init(@lang, @script, isodoc.i18n)
115
+ isodoc.info(@xml, nil)
116
+ isodoc
117
+ end
118
+
119
+ def isodoc_populate(isodoc)
107
120
  # create the @meta class of isodoc, with "navigation" set to the index bar
108
121
  # extracted from the manifest
109
122
  nav = indexfile(@xml.at(ns("//manifest")))
110
123
  i18n = isodoc.i18n
111
- i18n.set(:navigation, nav)
124
+ i18n.set("navigation", nav)
112
125
  isodoc.metadata_init(@lang, @script, i18n)
113
126
  # populate the @meta class of isodoc with the various metadata fields
114
127
  # native to the flavour; used to populate Liquid
@@ -135,6 +148,8 @@ module Metanorma
135
148
  # populate liquid template of ARGV[1] with metadata extracted from
136
149
  # collection manifest
137
150
  def coverpage
151
+ return unless @coverpage
152
+
138
153
  File.open(File.join(@outdir, "index.html"), "w:UTF-8") do |f|
139
154
  f.write @isodoc.populate_template(File.read(@coverpage))
140
155
  end
@@ -163,11 +178,19 @@ module Metanorma
163
178
  # @param builder [Nokogiri::XML::Builder]
164
179
  def docrefs(elm, builder)
165
180
  elm.xpath(ns("./docref")).each do |d|
166
- identifier = d.at(ns("./identifier")).text
167
- link = if d["fileref"] then d["fileref"].sub(/\.xml$/, ".html")
168
- else d["id"] + ".html"
169
- end
170
- builder.li { builder.a identifier, href: link }
181
+ ident = d.at(ns("./identifier")).children.to_xml
182
+ builder.li do |li|
183
+ li.a **{ href: index_link(d, ident) } do |a|
184
+ a << ident
185
+ end
186
+ end
187
+ end
188
+ end
189
+
190
+ def index_link(docref, ident)
191
+ if docref["fileref"]
192
+ @files[ident][:out_path].sub(/\.xml$/, ".html")
193
+ else "#{docref['id']}.html"
171
194
  end
172
195
  end
173
196
 
@@ -193,14 +216,20 @@ module Metanorma
193
216
 
194
217
  private
195
218
 
219
+ def format_sort(formats)
220
+ ret = []
221
+ formats.include?(:xml) and ret << :xml
222
+ formats.include?(:presentation) and ret << :presentation
223
+ a = %i(presentation xml)
224
+ ret + formats.reject { |i| a.include? i }
225
+ end
226
+
196
227
  # @param options [Hash]
197
228
  # @raise [ArgumentError]
198
229
  def check_options(options)
199
230
  unless options[:format].is_a?(Array) && (FORMATS & options[:format]).any?
200
231
  raise ArgumentError, "Need to specify formats (xml,html,pdf,doc)"
201
232
  end
202
- return if !options[:format].include?(:html) || options[:coverpage]
203
- raise ArgumentError, "Need to specify a coverpage to render HTML"
204
233
  end
205
234
  end
206
235
  end
@@ -6,6 +6,7 @@ require "fontist"
6
6
  require "fontist/manifest/install"
7
7
  require_relative "compile_validate"
8
8
  require_relative "fontist_utils"
9
+ require_relative "util"
9
10
 
10
11
  module Metanorma
11
12
  class Compile
@@ -20,7 +21,7 @@ module Metanorma
20
21
  def compile(filename, options = {})
21
22
  require_libraries(options)
22
23
  options = options_extract(filename, options)
23
- validate_type(options) && validate_format(options) || (return nil)
24
+ validate_options(options)
24
25
  @processor = @registry.find_processor(options[:type].to_sym)
25
26
  extensions = get_extensions(options) or return nil
26
27
  (file, isodoc = process_input(filename, options)) or return nil
@@ -35,7 +36,7 @@ module Metanorma
35
36
  end
36
37
 
37
38
  def xml_options_extract(file)
38
- xml = Nokogiri::XML(file)
39
+ xml = Nokogiri::XML(file) { |config| config.huge }
39
40
  if xml.root
40
41
  @registry.root_tags.each do |k, v|
41
42
  return { type: k } if v == xml.root.name
@@ -74,7 +75,9 @@ module Metanorma
74
75
  memo
75
76
  end
76
77
  end
77
- if !extensions.include?(:presentation) and extensions.any? { |e| @processor.use_presentation_xml(e) }
78
+ if !extensions.include?(:presentation) && extensions.any? do |e|
79
+ @processor.use_presentation_xml(e)
80
+ end
78
81
  extensions << :presentation
79
82
  end
80
83
  extensions
@@ -88,7 +91,7 @@ module Metanorma
88
91
  options[:asciimath] and
89
92
  file.sub!(/^(=[^\n]+\n)/, "\\1:mn-keep-asciimath:\n")
90
93
  dir = File.dirname(filename)
91
- dir != '.' and
94
+ dir != "." and
92
95
  file.gsub!(/^include::/, "include::#{dir}/")
93
96
  [file, @processor.input_to_isodoc(file, filename, options)]
94
97
  when ".xml"
@@ -108,15 +111,17 @@ module Metanorma
108
111
 
109
112
  def relaton_export(isodoc, options)
110
113
  return unless options[:relaton]
111
- xml = Nokogiri::XML(isodoc)
114
+
115
+ xml = Nokogiri::XML(isodoc) { |config| config.huge }
112
116
  bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
113
- #docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
114
- #outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
117
+ # docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
118
+ # outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
115
119
  File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
116
120
  end
117
121
 
118
122
  def clean_sourcecode(xml)
119
- xml.xpath(".//callout | .//annotation | .//xmlns:callout | .//xmlns:annotation").each do |x|
123
+ xml.xpath(".//callout | .//annotation | .//xmlns:callout | "\
124
+ ".//xmlns:annotation").each do |x|
120
125
  x.remove
121
126
  end
122
127
  xml.xpath(".//br | .//xmlns:br").each { |x| x.replace("\n") }
@@ -125,12 +130,13 @@ module Metanorma
125
130
 
126
131
  def extract(isodoc, dirname, extract_types)
127
132
  return unless dirname
133
+
128
134
  if extract_types.nil? || extract_types.empty?
129
135
  extract_types = [:sourcecode, :image, :requirement]
130
136
  end
131
137
  FileUtils.rm_rf dirname
132
138
  FileUtils.mkdir_p dirname
133
- xml = Nokogiri::XML(isodoc)
139
+ xml = Nokogiri::XML(isodoc) { |config| config.huge }
134
140
  sourcecode_export(xml, dirname) if extract_types.include? :sourcecode
135
141
  image_export(xml, dirname) if extract_types.include? :image
136
142
  requirement_export(xml, dirname) if extract_types.include? :requirement
@@ -176,17 +182,6 @@ module Metanorma
176
182
  end
177
183
  end
178
184
 
179
- # dependency ordering
180
- def sort_extensions_execution(ext)
181
- case ext
182
- when :xml then 0
183
- when :rxl then 1
184
- when :presentation then 2
185
- else
186
- 99
187
- end
188
- end
189
-
190
185
  def wrap_html(options, file_extension, outfilename)
191
186
  if options[:wrapper] && /html$/.match(file_extension)
192
187
  outfilename = outfilename.sub(/\.html$/, "")
@@ -201,34 +196,22 @@ module Metanorma
201
196
  f = change_output_dir options
202
197
  xml_name = f.sub(/\.[^.]+$/, ".xml")
203
198
  presentationxml_name = f.sub(/\.[^.]+$/, ".presentation.xml")
204
- extensions.sort do |a, b|
205
- sort_extensions_execution(a) <=> sort_extensions_execution(b)
206
- end.each do |ext|
207
- isodoc_options = @processor.extract_options(file)
208
- isodoc_options[:datauriimage] = true if options[:datauriimage]
209
- isodoc_options[:sourcefilename] = options[:filename]
199
+ Util.sort_extensions_execution(extensions).each do |ext|
210
200
  file_extension = @processor.output_formats[ext]
211
201
  outfilename = f.sub(/\.[^.]+$/, ".#{file_extension}")
212
- if ext == :pdf
213
- font_locations = FontistUtils.fontist_font_locations(@processor, options)
214
- font_locations and
215
- isodoc_options[:mn2pdf] = { font_manifest_file: font_locations.path }
216
- end
202
+ isodoc_options = get_isodoc_options(file, options, ext)
217
203
  if ext == :rxl
218
204
  options[:relaton] = outfilename
219
205
  relaton_export(isodoc, options)
206
+ elsif options[:passthrough_presentation_xml] && ext == :presentation
207
+ FileUtils.cp f, presentationxml_name
220
208
  else
221
209
  begin
222
210
  @processor.use_presentation_xml(ext) ?
223
211
  @processor.output(nil, presentationxml_name, outfilename, ext, isodoc_options) :
224
212
  @processor.output(isodoc, xml_name, outfilename, ext, isodoc_options)
225
213
  rescue StandardError => e
226
- if e.message.start_with? "mn2pdf"
227
- @errors << e.message
228
- else
229
- puts e.message
230
- puts e.backtrace.join("\n")
231
- end
214
+ isodoc_error_process(e)
232
215
  end
233
216
  end
234
217
  wrap_html(options, file_extension, outfilename)
@@ -237,6 +220,28 @@ module Metanorma
237
220
 
238
221
  private
239
222
 
223
+ def isodoc_error_process(err)
224
+ if err.message.include? "Fatal:"
225
+ @errors << err.message
226
+ else
227
+ puts err.message
228
+ puts err.backtrace.join("\n")
229
+ end
230
+ end
231
+
232
+ def get_isodoc_options(file, options, ext)
233
+ isodoc_options = @processor.extract_options(file)
234
+ isodoc_options[:datauriimage] = true if options[:datauriimage]
235
+ isodoc_options[:sourcefilename] = options[:filename]
236
+ isodoc_options[:bare] = options[:bare]
237
+ isodoc_options[:sectionsplit] = options[:sectionsplit]
238
+ if ext == :pdf
239
+ floc = FontistUtils.fontist_font_locations(@processor, options) and
240
+ isodoc_options[:mn2pdf] = { font_manifest_file: floc.path }
241
+ end
242
+ isodoc_options
243
+ end
244
+
240
245
  # @param options [Hash]
241
246
  # @return [String]
242
247
  def change_output_dir(options)