metanorma 1.3.12 → 1.4.3

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
  SHA256:
3
- metadata.gz: 6e0318ba6a8281b9d412916b46fa57cc2de00a2738dd7703425c3f3736d92ae8
4
- data.tar.gz: 03d43c3e079517e202ba7e6d48f67ba792741db08ad026392169d19ffdc5a5d5
3
+ metadata.gz: d977a50a2b1b4c0a016439be744d32ef51fad6a4f0e5869f0ea31654065bb584
4
+ data.tar.gz: 3da646653cdea95e20f7e0c5ee07a9ccf301b4f73506d1f65059e03b71c064de
5
5
  SHA512:
6
- metadata.gz: 3cc705935cee37831ad02b8ca85f556f9d2ec8cec8c341a045f34d96621b20e79455533a22262004b363d6f10a1523505cea14bc489fa1d47d9406870e1acc7f
7
- data.tar.gz: a9d55375a16afb0ed0ee9e392dc2cc134f9a0e424fbadbb8f7b9f5fe940d944867c9d5e32e39f79fcf6d594381a7f2c90a9d70502b5108668c181e628e32f83e
6
+ metadata.gz: be99d0c2c11598c9e5dcd05df5da7a1bcdf49a161a56928ef8c1873bae349b401823d5f112b2aa4e0350bc20511125921c626fbd4c7ef862f6291476a409281c
7
+ data.tar.gz: aaba4884d254314d5f3436d6f709503a34810398f093e1010cb4186c2bb1fcd7ebc1b41725dc0542db3ce4a7896f151b826a146332d3a4a2fffb0be47f9a3482
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gemspec
9
9
  if File.exist? "Gemfile.devel"
10
10
  eval File.read("Gemfile.devel"), nil, "Gemfile.devel" # rubocop:disable Security/Eval
11
11
  end
12
+
@@ -91,12 +91,9 @@ module Metanorma
91
91
  private
92
92
 
93
93
  def parse_xml(file)
94
- xml = Nokogiri::XML File.read(file, encoding: "UTF-8") do |config|
95
- config.huge
96
- end
97
- if (b = xml.at("/xmlns:metanorma-collection/xmlns:bibdata"))
98
- bd = Relaton::Cli.parse_xml b
99
- end
94
+ xml = Nokogiri::XML File.read(file, encoding: "UTF-8") { |c| c.huge }
95
+ (b = xml.at("/xmlns:metanorma-collection/xmlns:bibdata")) and
96
+ bd = Relaton::Cli.parse_xml(b)
100
97
  mnf_xml = xml.at("/xmlns:metanorma-collection/xmlns:manifest")
101
98
  mnf = CollectionManifest.from_xml mnf_xml
102
99
  pref = pref_final_content xml.at("//xmlns:prefatory-content")
@@ -83,11 +83,15 @@ module Metanorma
83
83
  add_document_suffix(identifier, docxml)
84
84
  update_direct_refs_to_docs(docxml, identifier)
85
85
  svgmap_resolve(datauri_encode(docxml))
86
+ hide_refs(docxml)
87
+ docxml.to_xml
88
+ end
89
+
90
+ def hide_refs(docxml)
86
91
  docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or "\
87
92
  "@hidden = 'false'])]")).each do |f|
88
93
  f["hidden"] = "true"
89
94
  end
90
- docxml.to_xml
91
95
  end
92
96
 
93
97
  def supply_repo_ids(docxml)
@@ -97,7 +101,8 @@ module Metanorma
97
101
  b.xpath(ns("./docidentifier")).each do |d|
98
102
  next unless @files[d.text]
99
103
 
100
- d.next = "<docidentifier type='repository'>current-metanorma-collection/#{d.text}"
104
+ d.next = "<docidentifier type='repository'>"\
105
+ "current-metanorma-collection/#{d.text}"
101
106
  end
102
107
  end
103
108
  end
@@ -111,29 +116,30 @@ module Metanorma
111
116
 
112
117
  def svgmap_resolve(docxml)
113
118
  isodoc = IsoDoc::Convert.new({})
119
+ isodoc.bibitem_lookup(docxml)
114
120
  docxml.xpath(ns("//svgmap//eref")).each do |e|
115
- href = isodoc.eref_target(e)
116
- next if href == "##{e['bibitemid']}" ||
117
- href =~ /^#/ && !docxml.at("//*[@id = '#{href.sub(/^#/, '')}']")
118
-
119
- e["target"] = href.strip
120
- e.name = "link"
121
- e&.elements&.remove
121
+ svgmap_resolve1(e, isodoc)
122
122
  end
123
123
  Metanorma::Utils::svgmap_rewrite(docxml, "")
124
124
  end
125
125
 
126
+ def svgmap_resolve1(eref, isodoc)
127
+ href = isodoc.eref_target(eref)
128
+ return if href == "##{eref['bibitemid']}" ||
129
+ (href =~ /^#/ && !docxml.at("//*[@id = '#{href.sub(/^#/, '')}']"))
130
+
131
+ eref["target"] = href.strip
132
+ eref.name = "link"
133
+ eref&.elements&.remove
134
+ end
135
+
126
136
  # repo(current-metanorma-collection/ISO 17301-1:2016)
127
137
  # replaced by bibdata of "ISO 17301-1:2016" in situ as bibitem.
128
138
  # Any erefs to that bibitem id are replaced with relative URL
129
139
  # Preferably with anchor, and is a job to realise dynamic lookup
130
140
  # of localities.
131
141
  def update_direct_refs_to_docs(docxml, identifier)
132
- erefs = docxml.xpath(ns("//eref"))
133
- .each_with_object({ citeas: {}, bibitemid: {} }) do |i, m|
134
- m[:citeas][i["citeas"]] = true
135
- m[:bibitemid][i["bibitemid"]] = true
136
- end
142
+ erefs = collect_erefs(docxml)
137
143
  docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
138
144
  docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
139
145
  next unless docid && %r{^current-metanorma-collection/}.match(docid)
@@ -144,6 +150,14 @@ module Metanorma
144
150
  end
145
151
  end
146
152
 
153
+ def collect_erefs(docxml)
154
+ docxml.xpath(ns("//eref"))
155
+ .each_with_object({ citeas: {}, bibitemid: {} }) do |i, m|
156
+ m[:citeas][i["citeas"]] = true
157
+ m[:bibitemid][i["bibitemid"]] = true
158
+ end
159
+ end
160
+
147
161
  # Resolve erefs to a container of ids in another doc,
148
162
  # to an anchor eref (direct link)
149
163
  def update_indirect_refs_to_docs(docxml, internal_refs)
@@ -99,17 +99,15 @@ module Metanorma
99
99
  out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
100
100
  ret = if ref["fileref"]
101
101
  { type: "fileref", ref: @documents[identifier].file,
102
- rel_path: ref["fileref"],
103
- out_path: out }
104
- else
105
- { type: "id", ref: ref["id"] }
102
+ rel_path: ref["fileref"], out_path: out }
103
+ else { type: "id", ref: ref["id"] }
106
104
  end
107
105
  %i(attachment sectionsplit index).each do |s|
108
106
  ret[s] = ref[s.to_s] if ref[s.to_s]
109
107
  end
110
- ret[:presentationxml] = ref["presentation-xml"] if ref["presentation-xml"]
111
- ret[:bareafterfirst] = ref["bare-after-first"] if ref["bare-after-first"]
112
- ret
108
+ ret[:presentationxml] = ref["presentation-xml"]
109
+ ret[:bareafterfirst] = ref["bare-after-first"]
110
+ ret.compact
113
111
  end
114
112
 
115
113
  def add_suffix_to_attributes(doc, suffix, tag_name, attribute_name)
@@ -164,10 +162,15 @@ module Metanorma
164
162
  def file_compile(file, filename, identifier)
165
163
  return if @files[identifier][:sectionsplit] == "true"
166
164
 
167
- @compile.compile file.path, { format: :asciidoc, extension_keys: @format }
168
- .merge(compile_options(identifier))
165
+ opts = {
166
+ format: :asciidoc,
167
+ extension_keys: @format,
168
+ output_dir: @outdir,
169
+ }.merge(compile_options(identifier))
170
+
171
+ @compile.compile file, opts
169
172
  @files[identifier][:outputs] = {}
170
- file_compile_formats(file, filename, identifier)
173
+ file_compile_formats(filename, identifier)
171
174
  end
172
175
 
173
176
  def compile_options(identifier)
@@ -182,29 +185,18 @@ module Metanorma
182
185
  ret
183
186
  end
184
187
 
185
- def file_compile_formats(file, filename, identifier)
188
+ def file_compile_formats(filename, identifier)
189
+ file_id = @files[identifier]
190
+ @format << :presentation if @format.include?(:pdf)
186
191
  @format.each do |e|
187
192
  ext = @compile.processor.output_formats[e]
188
193
  fn = File.basename(filename).sub(/(?<=\.)[^.]+$/, ext.to_s)
189
- if /html$/.match?(ext) && @files[identifier][:sectionsplit]
190
- # file_sectionsplit_copy(file, fn, identifier, ext, e)
191
- else
192
- FileUtils.cp file.path.sub(/\.xml$/, ".#{ext}"),
193
- File.join(@outdir, fn)
194
- @files[identifier][:outputs][e] = File.join(@outdir, fn)
194
+ unless /html$/.match?(ext) && file_id[:sectionsplit]
195
+ file_id[:outputs][e] = File.join(@outdir, fn)
195
196
  end
196
197
  end
197
198
  end
198
199
 
199
- def file_sectionsplit_copy(file, base, identifier, ext, format)
200
- dir = file.path.sub(/\.xml$/, ".#{ext}_collection")
201
- files = Dir.glob("#{dir}/*.#{ext}")
202
- FileUtils.cp files, @outdir
203
- cover = File.join(@outdir, base.sub(/\.html$/, ".index.html"))
204
- FileUtils.cp File.join(dir, "index.html"), cover
205
- @files[identifier][:outputs][format] = cover
206
- end
207
-
208
200
  def copy_file_to_dest(fileref)
209
201
  dest = File.join(@outdir, fileref[:out_path])
210
202
  FileUtils.mkdir_p(File.dirname(dest))
@@ -223,12 +215,13 @@ module Metanorma
223
215
  else
224
216
  file, filename = targetfile(x, read: true)
225
217
  warn "\n\n\n\n\nProcess #{filename}: #{DateTime.now.strftime('%H:%M:%S')}"
226
- file = update_xrefs(file, identifier, internal_refs)
227
- Tempfile.open(["collection", ".xml"], encoding: "utf-8") do |f|
228
- f.write(file)
229
- f.close
230
- file_compile(f, filename, identifier)
231
- end
218
+ collection_xml = update_xrefs(file, identifier, internal_refs)
219
+ collection_filename = File.basename(filename, File.extname(filename))
220
+ collection_xml_path = File.join(Dir.tmpdir,
221
+ "#{collection_filename}.xml")
222
+ File.write collection_xml_path, collection_xml, encoding: "UTF-8"
223
+ file_compile(collection_xml_path, filename, identifier)
224
+ FileUtils.rm(collection_xml_path)
232
225
  end
233
226
  end
234
227
  end
@@ -62,7 +62,6 @@ module Metanorma
62
62
  # @option options [Strong] :ourput_folder output directory
63
63
  def self.render(col, options = {})
64
64
  folder = File.dirname col.file
65
- # require "byebug"; byebug
66
65
  warn "\n\n\n\n\nRender Init: #{DateTime.now.strftime('%H:%M:%S')}"
67
66
  cr = new(col, folder, options)
68
67
  warn "\n\n\n\n\nRender Files: #{DateTime.now.strftime('%H:%M:%S')}"
@@ -104,13 +103,15 @@ module Metanorma
104
103
 
105
104
  class PdfOptionsNode
106
105
  def initialize(doctype, options)
107
- doc_proc = Metanorma::Registry.instance.find_processor(doctype)
108
- @font_locations = FontistUtils.fontist_font_locations(doc_proc, options)
106
+ docproc = Metanorma::Registry.instance.find_processor(doctype)
107
+ if FontistUtils.has_fonts_manifest?(docproc, options)
108
+ @fonts_manifest = FontistUtils.location_manifest(docproc)
109
+ end
109
110
  end
110
111
 
111
112
  def attr(key)
112
- if key == "mn2pdf-font-manifest-file" && @font_locations
113
- @font_locations.path
113
+ if key == "fonts-manifest" && @font_locations
114
+ @fonts_manifest
114
115
  end
115
116
  end
116
117
  end
@@ -8,6 +8,7 @@ require_relative "compile_validate"
8
8
  require_relative "fontist_utils"
9
9
  require_relative "util"
10
10
  require_relative "sectionsplit"
11
+ require_relative "extract"
11
12
 
12
13
  module Metanorma
13
14
  class Compile
@@ -32,7 +33,7 @@ module Metanorma
32
33
  extract(isodoc, options[:extract], options[:extract_type])
33
34
  FontistUtils.install_fonts(@processor, options) unless @fontist_installed
34
35
  @fontist_installed = true
35
- process_extensions(extensions, file, isodoc, options)
36
+ process_extensions(filename, extensions, file, isodoc, options)
36
37
  end
37
38
 
38
39
  def require_libraries(options)
@@ -118,75 +119,9 @@ module Metanorma
118
119
  File.read(filename, encoding: "utf-8").gsub("\r\n", "\n")
119
120
  end
120
121
 
121
- def relaton_export(isodoc, options)
122
- return unless options[:relaton]
123
-
124
- xml = Nokogiri::XML(isodoc) { |config| config.huge }
125
- bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
126
- # docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
127
- # outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
128
- File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
129
- end
130
-
131
- def clean_sourcecode(xml)
132
- xml.xpath(".//callout | .//annotation | .//xmlns:callout | "\
133
- ".//xmlns:annotation").each(&:remove)
134
- xml.xpath(".//br | .//xmlns:br").each { |x| x.replace("\n") }
135
- HTMLEntities.new.decode(xml.children.to_xml)
136
- end
137
-
138
- def extract(isodoc, dirname, extract_types)
139
- return unless dirname
140
-
141
- if extract_types.nil? || extract_types.empty?
142
- extract_types = %i[sourcecode image requirement]
143
- end
144
- FileUtils.rm_rf dirname
145
- FileUtils.mkdir_p dirname
146
- xml = Nokogiri::XML(isodoc) { |config| config.huge }
147
- sourcecode_export(xml, dirname) if extract_types.include? :sourcecode
148
- image_export(xml, dirname) if extract_types.include? :image
149
- requirement_export(xml, dirname) if extract_types.include? :requirement
150
- end
151
-
152
- def sourcecode_export(xml, dirname)
153
- xml.at("//sourcecode | //xmlns:sourcecode") or return
154
- FileUtils.mkdir_p "#{dirname}/sourcecode"
155
- xml.xpath("//sourcecode | //xmlns:sourcecode").each_with_index do |s, i|
156
- filename = s["filename"] || sprintf("sourcecode-%04d.txt", i)
157
- File.open("#{dirname}/sourcecode/#{filename}", "w:UTF-8") do |f|
158
- f.write clean_sourcecode(s.dup)
159
- end
160
- end
161
- end
162
-
163
- def image_export(xml, dirname)
164
- xml.at("//image | //xmlns:image") or return
165
- FileUtils.mkdir_p "#{dirname}/image"
166
- xml.xpath("//image | //xmlns:image").each_with_index do |s, i|
167
- next unless /^data:image/.match? s["src"]
168
-
169
- %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ s["src"]
170
- filename = s["filename"] || sprintf("image-%04d.%s", i, imgtype)
171
- File.open("#{dirname}/image/#{filename}", "wb") do |f|
172
- f.write(Base64.strict_decode64(imgdata))
173
- end
174
- end
175
- end
176
-
177
- REQUIREMENT_XPATH = "//requirement | //xmlns:requirement | "\
178
- "//recommendation | //xmlns:recommendation | //permission | "\
179
- "//xmlns:permission".freeze
180
-
181
- def requirement_export(xml, dirname)
182
- xml.at(REQUIREMENT_XPATH) or return
183
- FileUtils.mkdir_p "#{dirname}/requirement"
184
- xml.xpath(REQUIREMENT_XPATH).each_with_index do |s, i|
185
- filename = s["filename"] || sprintf("%s-%04d.xml", s.name, i)
186
- File.open("#{dirname}/requirement/#{filename}", "w:UTF-8") do |f|
187
- f.write s
188
- end
189
- end
122
+ def export_output(fname, content, **options)
123
+ mode = options[:binary] ? "wb" : "w:UTF-8"
124
+ File.open(fname, mode) { |f| f.write content }
190
125
  end
191
126
 
192
127
  def wrap_html(options, file_extension, outfilename)
@@ -199,39 +134,43 @@ module Metanorma
199
134
  end
200
135
 
201
136
  # isodoc is Raw Metanorma XML
202
- def process_extensions(extensions, file, isodoc, options)
137
+ def process_extensions(filename, extensions, file, isodoc, options)
203
138
  f = change_output_dir options
204
- xml_name = f.sub(/\.[^.]+$/, ".xml")
205
- presentationxml_name = f.sub(/\.[^.]+$/, ".presentation.xml")
139
+ name = { xml: f.sub(/\.[^.]+$/, ".xml"),
140
+ presentationxml: f.sub(/\.[^.]+$/, ".presentation.xml") }
206
141
  Util.sort_extensions_execution(extensions).each do |ext|
207
142
  file_extension = @processor.output_formats[ext]
208
- outfilename = f.sub(/\.[^.]+$/, ".#{file_extension}")
143
+ name[:out] = f.sub(/\.[^.]+$/, ".#{file_extension}")
209
144
  isodoc_options = get_isodoc_options(file, options, ext)
210
145
  if ext == :rxl
211
- relaton_export(isodoc, options.merge(relaton: outfilename))
146
+ relaton_export(isodoc, options.merge(relaton: name[:out]))
212
147
  elsif options[:passthrough_presentation_xml] && ext == :presentation
213
- FileUtils.cp f, presentationxml_name
148
+ FileUtils.cp filename, name[:presentationxml]
214
149
  elsif ext == :html && options[:sectionsplit]
215
- sectionsplit_convert(xml_name, isodoc, outfilename, isodoc_options)
150
+ sectionsplit_convert(name[:xml], isodoc, name[:out], isodoc_options)
216
151
  else
217
- if ext == :pdf
218
- floc = FontistUtils.fontist_font_locations(@processor, options)
219
- isodoc_options[:mn2pdf] = { font_manifest_file: floc.path } if floc
220
- end
221
- begin
222
- if @processor.use_presentation_xml(ext)
223
- @processor.output(nil, presentationxml_name, outfilename, ext,
224
- isodoc_options)
225
- else
226
- @processor.output(isodoc, xml_name, outfilename, ext,
227
- isodoc_options)
228
- end
229
- rescue StandardError => e
230
- isodoc_error_process(e)
152
+ if ext == :pdf && FontistUtils.has_fonts_manifest?(@processor,
153
+ options)
154
+ isodoc_options[:mn2pdf] = {
155
+ font_manifest: FontistUtils.location_manifest(@processor),
156
+ }
231
157
  end
158
+ process_extensions1(ext, name, isodoc, isodoc_options)
232
159
  end
233
- wrap_html(options, file_extension, outfilename)
160
+ wrap_html(options, file_extension, name[:out])
161
+ end
162
+ end
163
+
164
+ def process_extensions1(ext, fnames, isodoc, isodoc_options)
165
+ if @processor.use_presentation_xml(ext)
166
+ @processor.output(nil, fnames[:presentationxml], fnames[:out], ext,
167
+ isodoc_options)
168
+ else
169
+ @processor.output(isodoc, fnames[:xml], fnames[:out], ext,
170
+ isodoc_options)
234
171
  end
172
+ rescue StandardError => e
173
+ isodoc_error_process(e)
235
174
  end
236
175
 
237
176
  private
@@ -245,7 +184,7 @@ module Metanorma
245
184
  end
246
185
  end
247
186
 
248
- def get_isodoc_options(file, options, ext)
187
+ def get_isodoc_options(file, options, _ext)
249
188
  isodoc_options = @processor.extract_options(file)
250
189
  isodoc_options[:datauriimage] = true if options[:datauriimage]
251
190
  isodoc_options[:sourcefilename] = options[:filename]
@@ -0,0 +1,72 @@
1
+ module Metanorma
2
+ class Compile
3
+ def relaton_export(isodoc, options)
4
+ return unless options[:relaton]
5
+
6
+ xml = Nokogiri::XML(isodoc) { |config| config.huge }
7
+ bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
8
+ # docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
9
+ # outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
10
+ File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
11
+ end
12
+
13
+ def clean_sourcecode(xml)
14
+ xml.xpath(".//callout | .//annotation | .//xmlns:callout | "\
15
+ ".//xmlns:annotation").each(&:remove)
16
+ xml.xpath(".//br | .//xmlns:br").each { |x| x.replace("\n") }
17
+ HTMLEntities.new.decode(xml.children.to_xml)
18
+ end
19
+
20
+ def extract(isodoc, dirname, extract_types)
21
+ return unless dirname
22
+
23
+ extract_types.nil? || extract_types.empty? and
24
+ extract_types = %i[sourcecode image requirement]
25
+ FileUtils.rm_rf dirname
26
+ FileUtils.mkdir_p dirname
27
+ xml = Nokogiri::XML(isodoc) { |config| config.huge }
28
+ sourcecode_export(xml, dirname) if extract_types.include? :sourcecode
29
+ image_export(xml, dirname) if extract_types.include? :image
30
+ extract_types.include?(:requirement) and
31
+ requirement_export(xml, dirname)
32
+ end
33
+
34
+ def sourcecode_export(xml, dirname)
35
+ xml.at("//sourcecode | //xmlns:sourcecode") or return
36
+ FileUtils.mkdir_p "#{dirname}/sourcecode"
37
+ xml.xpath("//sourcecode | //xmlns:sourcecode").each_with_index do |s, i|
38
+ filename = s["filename"] || sprintf("sourcecode-%04d.txt", i)
39
+ export_output("#{dirname}/sourcecode/#{filename}",
40
+ clean_sourcecode(s.dup))
41
+ end
42
+ end
43
+
44
+ def image_export(xml, dirname)
45
+ xml.at("//image | //xmlns:image") or return
46
+ FileUtils.mkdir_p "#{dirname}/image"
47
+ xml.xpath("//image | //xmlns:image").each_with_index do |s, i|
48
+ next unless /^data:image/.match? s["src"]
49
+
50
+ %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ s["src"]
51
+ fn = s["filename"] || sprintf("image-%<num>04d.%<name>s",
52
+ num: i, name: imgtype)
53
+ export_output("#{dirname}/image/#{fn}", Base64.strict_decode64(imgdata),
54
+ binary: true)
55
+ end
56
+ end
57
+
58
+ REQUIREMENT_XPATH =
59
+ "//requirement | //xmlns:requirement | //recommendation | "\
60
+ "//xmlns:recommendation | //permission | //xmlns:permission".freeze
61
+
62
+ def requirement_export(xml, dirname)
63
+ xml.at(REQUIREMENT_XPATH) or return
64
+ FileUtils.mkdir_p "#{dirname}/requirement"
65
+ xml.xpath(REQUIREMENT_XPATH).each_with_index do |s, i|
66
+ fn = s["filename"] ||
67
+ sprintf("%<name>s-%<num>04d.xml", name: s.name, num: i)
68
+ export_output("#{dirname}/requirement/#{fn}", s)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -16,9 +16,9 @@ module Metanorma
16
16
  Util.log("[fontist] Skip font installation because" \
17
17
  " --no-install-fonts argument passed", :debug)
18
18
  return false
19
- elsif missing_fontist_manifest?(processor)
19
+ elsif !has_fonts_manifest?(processor)
20
20
  Util.log("[fontist] Skip font installation because "\
21
- "font_manifest is missing", :debug)
21
+ "fonts_manifest is missing", :debug)
22
22
  return false
23
23
  end
24
24
  true
@@ -27,26 +27,42 @@ module Metanorma
27
27
  def install_fonts_safe(manifest, agree, continue, no_progress)
28
28
  fontist_install(manifest, agree, no_progress)
29
29
  rescue Fontist::Errors::LicensingError
30
+ license_error_log(continue)
31
+ rescue Fontist::Errors::FontError => e
32
+ log_level = continue ? :warning : :fatal
33
+ Util.log("[fontist] '#{e.font}' font is not supported. " \
34
+ "Please report this issue at github.com/metanorma/metanorma" \
35
+ "/issues to report this issue.", log_level)
36
+ rescue Fontist::Errors::FormulaIndexNotFoundError
37
+ fintist_update_repo(manifest, agree, continue, no_progress)
38
+ end
39
+
40
+ def fontist_install(manifest, agree, no_progress)
41
+ Fontist::Manifest::Install.from_hash(
42
+ manifest,
43
+ confirmation: agree ? "yes" : "no",
44
+ no_progress: no_progress,
45
+ )
46
+ end
47
+
48
+ def license_error_log(continue)
30
49
  if continue
31
50
  Util.log(
32
51
  "[fontist] Processing will continue without fonts installed",
33
- :debug
52
+ :debug,
34
53
  )
35
54
  else
36
55
  Util.log("[fontist] Aborting without proper fonts installed," \
37
56
  " make sure that you have set option --agree-to-terms",
38
57
  :fatal)
39
58
  end
40
- rescue Fontist::Errors::FontError => e
41
- log_level = continue ? :warning : :fatal
42
- Util.log("[fontist] '#{e.font}' font is not supported. " \
43
- "Please report this issue at github.com/metanorma/metanorma" \
44
- "/issues to report this issue.", log_level)
45
- rescue Fontist::Errors::FormulaIndexNotFoundError
59
+ end
60
+
61
+ def fintist_update_repo(manifest, agree, continue, no_progress)
46
62
  if @@updated_formulas_repo
47
63
  Util.log(
48
64
  "[fontist] Bug: formula index not found after 'fontist update'",
49
- :fatal
65
+ :fatal,
50
66
  )
51
67
  end
52
68
  Util.log("[fontist] Missing formula index. Fetching it...", :debug)
@@ -54,28 +70,6 @@ module Metanorma
54
70
  @@updated_formulas_repo = true
55
71
  install_fonts_safe(manifest, agree, continue, no_progress)
56
72
  end
57
-
58
- def fontist_install(manifest, agree, no_progress)
59
- Fontist::Manifest::Install.from_hash(
60
- manifest,
61
- confirmation: agree ? "yes" : "no",
62
- no_progress: no_progress
63
- )
64
- end
65
-
66
- def dump_fontist_manifest_locations(manifest)
67
- location_manifest = Fontist::Manifest::Locations.from_hash(
68
- manifest
69
- )
70
- location_manifest_file = Tempfile.new(["fontist_locations", ".yml"])
71
- location_manifest_file.write location_manifest.to_yaml
72
- location_manifest_file.flush
73
- location_manifest_file
74
- end
75
-
76
- def missing_fontist_manifest?(processor)
77
- !processor.respond_to?(:fonts_manifest) || processor.fonts_manifest.nil?
78
- end
79
73
  end
80
74
 
81
75
  def self.install_fonts(processor, options)
@@ -89,20 +83,18 @@ module Metanorma
89
83
  manifest,
90
84
  agree_to_terms,
91
85
  can_without_fonts,
92
- no_progress
86
+ no_progress,
93
87
  )
94
88
  end
95
89
 
96
- def self.fontist_font_locations(processor, options)
97
- if missing_fontist_manifest?(processor) || options[:no_install_fonts]
98
- return nil
99
- end
100
-
101
- dump_fontist_manifest_locations(processor.fonts_manifest)
102
- rescue Fontist::Errors::FormulaIndexNotFoundError
103
- raise unless options[:continue_without_fonts]
90
+ def self.has_fonts_manifest?(processor, options = {})
91
+ !options[:no_install_fonts] \
92
+ && processor.respond_to?(:fonts_manifest) \
93
+ && !processor.fonts_manifest.nil?
94
+ end
104
95
 
105
- nil
96
+ def self.location_manifest(processor)
97
+ Fontist::Manifest::Locations.from_hash(processor.fonts_manifest)
106
98
  end
107
99
  end
108
100
  end
@@ -56,13 +56,19 @@ module Metanorma
56
56
  attr&.sub(/^#{name}:\s*$/, "#{name}: true")&.sub(/^#{name}:\s+/, "")
57
57
  end
58
58
 
59
- ADOC_OPTIONS = %w(htmlstylesheet htmlcoverpage htmlintropage scripts
60
- scripts-override scripts-pdf wordstylesheet i18nyaml
61
- standardstylesheet header wordcoverpage wordintropage
62
- ulstyle olstyle htmlstylesheet-override bare
63
- htmltoclevels doctoclevels sectionsplit base-asset-path
64
- body-font header-font monospace-font title-font
65
- align-cross-elements wordstylesheet-override).freeze
59
+ ADOC_OPTIONS =
60
+ %w(htmlstylesheet htmlcoverpage htmlintropage scripts
61
+ scripts-override scripts-pdf wordstylesheet i18nyaml
62
+ standardstylesheet header wordcoverpage wordintropage
63
+ ulstyle olstyle htmlstylesheet-override bare
64
+ htmltoclevels doctoclevels sectionsplit base-asset-path
65
+ body-font header-font monospace-font title-font
66
+ align-cross-elements wordstylesheet-override
67
+ pdf-encrypt pdf-encryption-length pdf-user-password
68
+ pdf-owner-password pdf-allow-copy-content pdf-allow-edit-content
69
+ pdf-allow-assemble-document pdf-allow-edit-annotations
70
+ pdf-allow-print pdf-allow-print-hq pdf-allow-fill-in-forms
71
+ pdf-allow-access-content pdf-encrypt-metadata).freeze
66
72
 
67
73
  def extract_options(file)
68
74
  header = file.sub(/\n\n.*$/m, "\n")
@@ -84,7 +90,7 @@ module Metanorma
84
90
  defined?(break_up) and
85
91
  break_up = empty_attr(break_up, "break-up-urls-in-tables")
86
92
  ret.merge(
87
- datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
93
+ datauriimage: defined?(datauriimage) ? datauriimage != "false" : true,
88
94
  suppressasciimathdup: defined?(suppress_asciimath_dup) ? suppress_asciimath_dup != "false" : nil,
89
95
  hierarchical_assets: defined?(hier_assets) ? hier_assets : nil,
90
96
  use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.3.12".freeze
2
+ VERSION = "1.4.3".freeze
3
3
  end
data/metanorma.gemspec CHANGED
@@ -34,13 +34,14 @@ Gem::Specification.new do |spec|
34
34
  # spec.add_dependency "relaton-cli"
35
35
  # spec.add_dependency "metanorma-standoc"
36
36
 
37
- spec.add_development_dependency "byebug", "~> 10.0"
37
+ spec.add_development_dependency "debug"
38
38
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
39
- spec.add_development_dependency "metanorma-iso", "~> 1.9.0"
39
+ spec.add_development_dependency "metanorma-iso", "~> 1.10"
40
+ spec.add_development_dependency "mnconvert"
40
41
  spec.add_development_dependency "rake", "~> 13.0"
41
42
  spec.add_development_dependency "rspec", "~> 3.0"
42
43
  spec.add_development_dependency "rspec-command", "~> 1.0"
43
44
  spec.add_development_dependency "rubocop", "~> 1.5.2"
44
45
  spec.add_development_dependency "sassc", "~> 2.4.0"
45
- spec.add_development_dependency "mnconvert"
46
+ spec.add_development_dependency "reline", "~> 0.2.8.pre.11"
46
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.12
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -109,19 +109,19 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: byebug
112
+ name: debug
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '10.0'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '10.0'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: equivalent-xml
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,28 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.9.0
145
+ version: '1.10'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.9.0
152
+ version: '1.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mnconvert
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rake
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -221,19 +235,19 @@ dependencies:
221
235
  - !ruby/object:Gem::Version
222
236
  version: 2.4.0
223
237
  - !ruby/object:Gem::Dependency
224
- name: mnconvert
238
+ name: reline
225
239
  requirement: !ruby/object:Gem::Requirement
226
240
  requirements:
227
- - - ">="
241
+ - - "~>"
228
242
  - !ruby/object:Gem::Version
229
- version: '0'
243
+ version: 0.2.8.pre.11
230
244
  type: :development
231
245
  prerelease: false
232
246
  version_requirements: !ruby/object:Gem::Requirement
233
247
  requirements:
234
- - - ">="
248
+ - - "~>"
235
249
  - !ruby/object:Gem::Version
236
- version: '0'
250
+ version: 0.2.8.pre.11
237
251
  description: Library to process any Metanorma standard.
238
252
  email:
239
253
  - open.source@ribose.com
@@ -274,6 +288,7 @@ files:
274
288
  - lib/metanorma/compile_validate.rb
275
289
  - lib/metanorma/config.rb
276
290
  - lib/metanorma/document.rb
291
+ - lib/metanorma/extract.rb
277
292
  - lib/metanorma/fontist_utils.rb
278
293
  - lib/metanorma/input.rb
279
294
  - lib/metanorma/input/asciidoc.rb
@@ -303,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
318
  - !ruby/object:Gem::Version
304
319
  version: '0'
305
320
  requirements: []
306
- rubygems_version: 3.1.4
321
+ rubygems_version: 3.2.32
307
322
  signing_key:
308
323
  specification_version: 4
309
324
  summary: Metanorma is the standard of standards; the metanorma gem allows you to create