metanorma 1.3.11 → 1.4.2

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: f054752f3bb51d3e1cfe983beaca06c817275d214d5652503a42325d93403a42
4
- data.tar.gz: 212a35305289d4286539dcdb008bf799fac028e87a84aab0a33b8137c73d84d5
3
+ metadata.gz: 539ee4d965aaed56cda517046d0a920d4ddebeba3844bac78107269c2cf5413e
4
+ data.tar.gz: 86dcc77ca4ced164f69bab210e004f02a3d4d23cecb9803c8a3d341deaf1964d
5
5
  SHA512:
6
- metadata.gz: c23014599c6a03a04b0dfa4fe93c6b300b0311ff55e552a5f1bd79a2d55220789c94916a9c6b694a044cd9247dcd95d1ab6dde05e0e7d949a29bcaedb07d8807
7
- data.tar.gz: 98da695a8d3cd9b93f244161b8e0874b7851bb6426fd686cabcafe493f8088b0af2923a216b2741d34a2532b8f76adc3ac377af1caa8a639fdd27ba4c1866ef7
6
+ metadata.gz: ac4a4d6372d7c76fa7013443d45e7ef21d503147ce16592041d041ce7015351a88af7fa28dd1b9e5db315ddf5d684389026f8a90d51ece750fc8e232b46c1d8c
7
+ data.tar.gz: 7a090eea1ff61230a291fe434f4a41ac882c51a51045404ab03010903799f8f666c7fab678b86e8fda062cfb0699a0c0f667dbad632f0682f4361b5b4acfd586
@@ -44,7 +44,7 @@ module Metanorma
44
44
  newbib = dup_bibitem(docid, bib)
45
45
  bib.replace(newbib)
46
46
  _file, url = targetfile(@files[docid], relative: true, read: false,
47
- doc: !@files[docid][:attachment])
47
+ doc: !@files[docid][:attachment])
48
48
  uri_node = Nokogiri::XML::Node.new "uri", newbib
49
49
  uri_node[:type] = "citation"
50
50
  uri_node.content = url
@@ -53,7 +53,7 @@ module Metanorma
53
53
 
54
54
  def fail_update_bibitem(docid, identifier)
55
55
  error = "[metanorma] Cannot find crossreference to document #{docid} "\
56
- "in document #{identifier}."
56
+ "in document #{identifier}."
57
57
  @log.add("Cross-References", nil, error)
58
58
  Util.log(error, :warning)
59
59
  end
@@ -78,6 +78,7 @@ module Metanorma
78
78
  # @return [String] XML content
79
79
  def update_xrefs(file, identifier, internal_refs)
80
80
  docxml = Nokogiri::XML(file) { |config| config.huge }
81
+ supply_repo_ids(docxml)
81
82
  update_indirect_refs_to_docs(docxml, internal_refs)
82
83
  add_document_suffix(identifier, docxml)
83
84
  update_direct_refs_to_docs(docxml, identifier)
@@ -89,6 +90,18 @@ module Metanorma
89
90
  docxml.to_xml
90
91
  end
91
92
 
93
+ def supply_repo_ids(docxml)
94
+ docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
95
+ next if b&.at(ns("./docidentifier[@type = 'repository']"))
96
+
97
+ b.xpath(ns("./docidentifier")).each do |d|
98
+ next unless @files[d.text]
99
+
100
+ d.next = "<docidentifier type='repository'>current-metanorma-collection/#{d.text}"
101
+ end
102
+ end
103
+ end
104
+
92
105
  def datauri_encode(docxml)
93
106
  docxml.xpath(ns("//image")).each do |i|
94
107
  i["src"] = Metanorma::Utils::datauri(i["src"])
@@ -161,7 +174,7 @@ module Metanorma
161
174
  if @files[docid] then update_anchor_loc(bib, e, docid)
162
175
  else
163
176
  e << "<strong>** Unresolved reference to document #{docid} "\
164
- "from eref</strong>"
177
+ "from eref</strong>"
165
178
  end
166
179
  end
167
180
  end
@@ -188,7 +201,7 @@ module Metanorma
188
201
  ref = ins&.at(ns("./locality/referenceFrom"))&.text
189
202
  anchor = @files[docid][:anchors].dig(type, ref) or return
190
203
  ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}"\
191
- "</referenceFrom></locality>"
204
+ "</referenceFrom></locality>"
192
205
  end
193
206
 
194
207
  # gather internal bibitem references
@@ -164,10 +164,15 @@ module Metanorma
164
164
  def file_compile(file, filename, identifier)
165
165
  return if @files[identifier][:sectionsplit] == "true"
166
166
 
167
- @compile.compile file.path, { format: :asciidoc, extension_keys: @format }
168
- .merge(compile_options(identifier))
167
+ opts = {
168
+ format: :asciidoc,
169
+ extension_keys: @format,
170
+ output_dir: @outdir,
171
+ }.merge(compile_options(identifier))
172
+
173
+ @compile.compile file, opts
169
174
  @files[identifier][:outputs] = {}
170
- file_compile_formats(file, filename, identifier)
175
+ file_compile_formats(filename, identifier)
171
176
  end
172
177
 
173
178
  def compile_options(identifier)
@@ -182,29 +187,17 @@ module Metanorma
182
187
  ret
183
188
  end
184
189
 
185
- def file_compile_formats(file, filename, identifier)
190
+ def file_compile_formats(filename, identifier)
191
+ file_id = @files[identifier]
186
192
  @format.each do |e|
187
193
  ext = @compile.processor.output_formats[e]
188
194
  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)
195
+ unless /html$/.match?(ext) && file_id[:sectionsplit]
196
+ file_id[:outputs][e] = File.join(@outdir, fn)
195
197
  end
196
198
  end
197
199
  end
198
200
 
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
201
  def copy_file_to_dest(fileref)
209
202
  dest = File.join(@outdir, fileref[:out_path])
210
203
  FileUtils.mkdir_p(File.dirname(dest))
@@ -223,12 +216,13 @@ module Metanorma
223
216
  else
224
217
  file, filename = targetfile(x, read: true)
225
218
  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
219
+ collection_xml = update_xrefs(file, identifier, internal_refs)
220
+ collection_filename = File.basename(filename, File.extname(filename))
221
+ collection_xml_path = File.join(Dir.tmpdir,
222
+ "#{collection_filename}.xml")
223
+ File.write collection_xml_path, collection_xml, encoding: "UTF-8"
224
+ file_compile(collection_xml_path, filename, identifier)
225
+ FileUtils.rm(collection_xml_path)
232
226
  end
233
227
  end
234
228
  end
@@ -104,13 +104,15 @@ module Metanorma
104
104
 
105
105
  class PdfOptionsNode
106
106
  def initialize(doctype, options)
107
- doc_proc = Metanorma::Registry.instance.find_processor(doctype)
108
- @font_locations = FontistUtils.fontist_font_locations(doc_proc, options)
107
+ docproc = Metanorma::Registry.instance.find_processor(doctype)
108
+ if FontistUtils.has_fonts_manifest?(docproc, options)
109
+ @fonts_manifest = FontistUtils.location_manifest(docproc)
110
+ end
109
111
  end
110
112
 
111
113
  def attr(key)
112
- if key == "mn2pdf-font-manifest-file" && @font_locations
113
- @font_locations.path
114
+ if key == "fonts-manifest" && @font_locations
115
+ @fonts_manifest
114
116
  end
115
117
  end
116
118
  end
@@ -32,7 +32,7 @@ module Metanorma
32
32
  extract(isodoc, options[:extract], options[:extract_type])
33
33
  FontistUtils.install_fonts(@processor, options) unless @fontist_installed
34
34
  @fontist_installed = true
35
- process_extensions(extensions, file, isodoc, options)
35
+ process_extensions(filename, extensions, file, isodoc, options)
36
36
  end
37
37
 
38
38
  def require_libraries(options)
@@ -199,7 +199,7 @@ module Metanorma
199
199
  end
200
200
 
201
201
  # isodoc is Raw Metanorma XML
202
- def process_extensions(extensions, file, isodoc, options)
202
+ def process_extensions(filename, extensions, file, isodoc, options)
203
203
  f = change_output_dir options
204
204
  xml_name = f.sub(/\.[^.]+$/, ".xml")
205
205
  presentationxml_name = f.sub(/\.[^.]+$/, ".presentation.xml")
@@ -210,10 +210,16 @@ module Metanorma
210
210
  if ext == :rxl
211
211
  relaton_export(isodoc, options.merge(relaton: outfilename))
212
212
  elsif options[:passthrough_presentation_xml] && ext == :presentation
213
- FileUtils.cp f, presentationxml_name
213
+ FileUtils.cp filename, presentationxml_name
214
214
  elsif ext == :html && options[:sectionsplit]
215
215
  sectionsplit_convert(xml_name, isodoc, outfilename, isodoc_options)
216
216
  else
217
+ if ext == :pdf && FontistUtils.has_fonts_manifest?(@processor,
218
+ options)
219
+ isodoc_options[:mn2pdf] = {
220
+ font_manifest: FontistUtils.location_manifest(@processor),
221
+ }
222
+ end
217
223
  begin
218
224
  if @processor.use_presentation_xml(ext)
219
225
  @processor.output(nil, presentationxml_name, outfilename, ext,
@@ -245,13 +251,10 @@ module Metanorma
245
251
  isodoc_options = @processor.extract_options(file)
246
252
  isodoc_options[:datauriimage] = true if options[:datauriimage]
247
253
  isodoc_options[:sourcefilename] = options[:filename]
248
- %i(bare sectionsplit no_install_fonts baseassetpath).each do |x|
254
+ %i(bare sectionsplit no_install_fonts baseassetpath aligncrosselements)
255
+ .each do |x|
249
256
  isodoc_options[x] ||= options[x]
250
257
  end
251
- if ext == :pdf
252
- floc = FontistUtils.fontist_font_locations(@processor, options) and
253
- isodoc_options[:mn2pdf] = { font_manifest_file: floc.path }
254
- end
255
258
  isodoc_options
256
259
  end
257
260
 
@@ -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
@@ -49,7 +49,7 @@ module Metanorma
49
49
  extensions: defined?(extensions) ? extensions : nil,
50
50
  relaton: defined?(relaton) ? relaton : nil,
51
51
  asciimath: asciimath,
52
- }.reject { |_, val| val.nil? }
52
+ }.compact
53
53
  end
54
54
 
55
55
  def empty_attr(attr, name)
@@ -62,7 +62,7 @@ module Metanorma
62
62
  ulstyle olstyle htmlstylesheet-override bare
63
63
  htmltoclevels doctoclevels sectionsplit base-asset-path
64
64
  body-font header-font monospace-font title-font
65
- wordstylesheet-override).freeze
65
+ align-cross-elements wordstylesheet-override).freeze
66
66
 
67
67
  def extract_options(file)
68
68
  header = file.sub(/\n\n.*$/m, "\n")
@@ -84,12 +84,12 @@ module Metanorma
84
84
  defined?(break_up) and
85
85
  break_up = empty_attr(break_up, "break-up-urls-in-tables")
86
86
  ret.merge(
87
- datauriimage: defined?(datauriimage) ? datauriimage != "false" : nil,
87
+ datauriimage: defined?(datauriimage) ? datauriimage != "false" : true,
88
88
  suppressasciimathdup: defined?(suppress_asciimath_dup) ? suppress_asciimath_dup != "false" : nil,
89
89
  hierarchical_assets: defined?(hier_assets) ? hier_assets : nil,
90
90
  use_xinclude: defined?(use_xinclude) ? use_xinclude : nil,
91
91
  break_up_urls_in_tables: defined?(break_up) ? break_up : nil,
92
- ).reject { |_, val| val.nil? }
92
+ ).compact
93
93
  end
94
94
  end
95
95
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.3.11".freeze
2
+ VERSION = "1.4.2".freeze
3
3
  end
data/metanorma.gemspec CHANGED
@@ -34,13 +34,13 @@ 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
39
  spec.add_development_dependency "metanorma-iso", "~> 1.9.0"
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
46
  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.11
4
+ version: 1.4.2
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-09-27 00:00:00.000000000 Z
11
+ date: 2021-11-29 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
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.9.0
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
@@ -220,20 +234,6 @@ dependencies:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
236
  version: 2.4.0
223
- - !ruby/object:Gem::Dependency
224
- name: mnconvert
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '0'
237
237
  description: Library to process any Metanorma standard.
238
238
  email:
239
239
  - open.source@ribose.com
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  - !ruby/object:Gem::Version
304
304
  version: '0'
305
305
  requirements: []
306
- rubygems_version: 3.1.4
306
+ rubygems_version: 3.2.22
307
307
  signing_key:
308
308
  specification_version: 4
309
309
  summary: Metanorma is the standard of standards; the metanorma gem allows you to create