metanorma 1.5.6 → 1.5.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8def7cdd4a8b5e3605736563382599b2d820b2c18e7305d6567c89b667c89d90
4
- data.tar.gz: 75b2d6a77b20a782ace64f18f112cae4bb5b5643172c4df31e05e3a4eb817f20
3
+ metadata.gz: 5a628508e5ba0e2e1d2ec4b77aa35866e67990ca67b38e34278e877b6e2ebee2
4
+ data.tar.gz: c6022674620272b5de0111fe182781b8d18d01bceb38c99b0eae92ad3a1265b6
5
5
  SHA512:
6
- metadata.gz: 5a95ed1b168dc0a1ce689a2d169f8664fdb087b35332f645836072ee3e13b8be63513ba585210c2f8f5e69d70161b3b1036dc34cc77a0659f14340caaf22d2e4
7
- data.tar.gz: 2cab73d708c92443edb99dcb7d761169de3fda2dca2fb40e364f374d085e34c1c7cc317ba3f192bbb98309c699719f97fc10552143c235642a610941189580a5
6
+ metadata.gz: e8dbe50e863d2ae58969dcccb4302425b2f1acca6a3200f3395b069bace35d57376d7b3fc054e99573f6cf4da8ff21539eb233ae6163b85894169247dd010634
7
+ data.tar.gz: 2590266e459d6f211470f5a6f3f282e78e06c5728780871ccf24e2c5069871c9c49fb37d32286cca6218f85ea21435e8c8b40437e07aca8cc2de673e65a71649
@@ -17,7 +17,7 @@ module Metanorma
17
17
  attr_accessor :directives
18
18
 
19
19
  # @return [Hash<String, Metanorma::Document>]
20
- attr_accessor :documents, :bibdatas
20
+ attr_accessor :documents, :bibdatas, :coverpage
21
21
 
22
22
  attr_accessor :disambig, :manifest
23
23
 
@@ -28,6 +28,7 @@ module Metanorma
28
28
  # @param manifest [Metanorma::CollectionManifest]
29
29
  # @param documents [Hash<String, Metanorma::Document>]
30
30
  # @param prefatory [String]
31
+ # @param coverpage [String]
31
32
  # @param final [String]
32
33
  # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
33
34
  def initialize(**args)
@@ -36,6 +37,10 @@ module Metanorma
36
37
  @bibdata = args[:bibdata]
37
38
  @manifest = args[:manifest]
38
39
  @manifest.collection = self
40
+ c = @directives.detect { |x| x.is_a?(Hash) && x["coverpage"] }
41
+ c and @coverpage = c["coverpage"]
42
+ c = @directives.detect { |x| x.is_a?(Hash) && x["coverpage-style"] }
43
+ c and @coverpage_style = c["coverpage-style"]
39
44
  @documents = args[:documents] || {}
40
45
  @bibdatas = args[:documents] || {}
41
46
  if @documents.any? && !@directives.include?("documents-inline")
@@ -68,12 +73,29 @@ module Metanorma
68
73
 
69
74
  def collection_body(coll)
70
75
  coll << @bibdata.to_xml(bibdata: true, date_format: :full)
76
+ @directives.each do |d|
77
+ coll << "<directives>#{obj_to_xml(d)}</directives>"
78
+ end
71
79
  @manifest.to_xml coll
72
80
  content_to_xml "prefatory", coll
73
81
  doccontainer coll
74
82
  content_to_xml "final", coll
75
83
  end
76
84
 
85
+ def obj_to_xml(elem)
86
+ case elem
87
+ when ::Array
88
+ elem.each_with_object([]) do |v, m|
89
+ m << "<value>#{obj_to_xml(v)}</value>"
90
+ end.join
91
+ when ::Hash
92
+ elem.each_with_object([]) do |(k, v), m|
93
+ m << "<#{k}>#{obj_to_xml(v)}</#{k}>"
94
+ end.join
95
+ else elem
96
+ end
97
+ end
98
+
77
99
  def render(opts)
78
100
  CollectionRenderer.render self, opts.merge(log: @log)
79
101
  clean_exit
@@ -100,10 +122,27 @@ module Metanorma
100
122
  mnf = CollectionManifest.from_xml mnf_xml
101
123
  pref = pref_final_content xml.at("//xmlns:prefatory-content")
102
124
  fnl = pref_final_content xml.at("//xmlns:final-content")
125
+ cov = pref_final_content xml.at("//xmlns:coverpage")
103
126
  new(file: file, bibdata: bd, manifest: mnf,
127
+ directives: directives_from_xml(xml.xpath("//xmlns:directives")),
104
128
  documents: docs_from_xml(xml, mnf),
105
129
  bibdatas: docs_from_xml(xml, mnf),
106
- prefatory: pref, final: fnl)
130
+ prefatory: pref, final: fnl, coverpage: cov)
131
+ end
132
+
133
+ # TODO refine
134
+ def directives_from_xml(dir)
135
+ dir.each_with_object([]) do |d, m|
136
+ if d.at("./xmlns:value")
137
+ m << x.xpath("./xmlns:value").map(&:text)
138
+ elsif d.at("./*")
139
+ out = d.elements.each_with_object({}) do |e, ret|
140
+ ret[e.name] = e.children.to_xml
141
+ end
142
+ m << out
143
+ else m << d.children.to_xml
144
+ end
145
+ end
107
146
  end
108
147
 
109
148
  def parse_yaml(file)
@@ -54,9 +54,9 @@ module Metanorma
54
54
  # IDs for repo references are untyped by default
55
55
  docid = bib.at(ns("./docidentifier[not(@type)]")) ||
56
56
  bib.at(ns("./docidentifier"))
57
- docid &&= docid.children.to_xml
58
- if @files[docid]
59
- docid
57
+ docid &&= @c.decode(@isodoc
58
+ .docid_prefix(docid["type"], docid.children.to_xml))
59
+ if @files[docid] then docid
60
60
  else
61
61
  fail_update_bibitem(docid, identifier)
62
62
  nil
@@ -111,11 +111,12 @@ module Metanorma
111
111
  docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
112
112
  next if b&.at(ns("./docidentifier[@type = 'repository']"))
113
113
 
114
- b.xpath(ns("./docidentifier")).each do |d|
115
- next unless @files[d.text]
116
-
117
- d.next = "<docidentifier type='repository'>" \
118
- "current-metanorma-collection/#{d.text}"
114
+ b.xpath(ns("./docidentifier")).each do |docid|
115
+ id = @c.decode(@isodoc
116
+ .docid_prefix(docid["type"], docid.children.to_xml))
117
+ @files[id] or next
118
+ docid.next = "<docidentifier type='repository'>" \
119
+ "current-metanorma-collection/#{id}"
119
120
  end
120
121
  end
121
122
  end
@@ -154,16 +155,21 @@ module Metanorma
154
155
  def update_direct_refs_to_docs(docxml, identifier)
155
156
  erefs = collect_erefs(docxml)
156
157
  docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
157
- docid = b.at(ns("./docidentifier[@type = 'repository']"))&.text
158
- next unless docid && %r{^current-metanorma-collection/}.match(docid)
159
-
158
+ docid = b.at(ns("./docidentifier[@type = 'repository']"))
159
+ (docid && %r{^current-metanorma-collection/}.match(docid.text)) or next
160
160
  update_bibitem(b, identifier)
161
- docid = b.at(ns("./docidentifier")) or next
162
- docid = docid.children.to_xml
161
+ docid = docid_to_citeas(b) or next
163
162
  erefs[:citeas][docid] and update_anchors(b, docxml, docid)
164
163
  end
165
164
  end
166
165
 
166
+ def docid_to_citeas(bib)
167
+ docid = bib.at(ns("./docidentifier[@primary = 'true']")) ||
168
+ bib.at(ns("./docidentifier")) or return
169
+ @c.decode(@isodoc
170
+ .docid_prefix(docid["type"], docid.children.to_xml))
171
+ end
172
+
167
173
  def collect_erefs(docxml)
168
174
  docxml.xpath(ns("//eref"))
169
175
  .each_with_object({ citeas: {}, bibitemid: {} }) do |i, m|
@@ -211,7 +217,7 @@ module Metanorma
211
217
  loc = eref.at(ns(".//locality[@type = 'anchor']")) or
212
218
  return update_anchor_create_loc(bib, eref, docid)
213
219
  document_suffix = Metanorma::Utils::to_ncname(docid)
214
- ref = loc.at(ns("./referenceFrom")) || return
220
+ ref = loc.at(ns("./referenceFrom")) or return
215
221
  anchor = "#{ref.text}_#{document_suffix}"
216
222
  return unless @files[docid][:anchors].inject([]) do |m, (_, x)|
217
223
  m += x.values
@@ -235,8 +241,7 @@ module Metanorma
235
241
  # gather internal bibitem references
236
242
  def gather_internal_refs
237
243
  @files.each_with_object({}) do |(_, x), refs|
238
- next if x[:attachment]
239
-
244
+ x[:attachment] and next
240
245
  file, = targetfile(x, read: true)
241
246
  Nokogiri::XML(file)
242
247
  .xpath(ns("//bibitem[@type = 'internal']/" \
@@ -253,7 +258,8 @@ module Metanorma
253
258
  def locate_internal_refs
254
259
  refs = gather_internal_refs
255
260
  @files.keys.reject { |k| @files[k][:attachment] }.each do |identifier|
256
- locate_internal_refs1(refs, identifier, @files[identifier])
261
+ id = @c.decode(@isodoc.docid_prefix("", identifier.dup))
262
+ locate_internal_refs1(refs, identifier, @files[id])
257
263
  end
258
264
  refs.each do |schema, ids|
259
265
  ids.each do |id, key|
@@ -15,8 +15,10 @@ 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")).children.to_xml
19
- files[identifier] = file_entry(d, identifier, path)
18
+ orig_id = d.at(ns("./identifier"))
19
+ identifier = @c.decode(@isodoc
20
+ .docid_prefix(orig_id["type"], orig_id.children.to_xml))
21
+ files[identifier] = file_entry(d, orig_id.children.to_xml, path)
20
22
  if files[identifier][:attachment]
21
23
  files[identifier][:bibdata] = Metanorma::Document
22
24
  .attachment_bibitem(identifier).root
@@ -95,6 +97,7 @@ module Metanorma
95
97
  # rel_path is the source file address, determined relative to the YAML.
96
98
  # out_path is the destination file address, with any references outside
97
99
  # the working directory (../../...) truncated
100
+ # identifier is the id with only spaces, no nbsp
98
101
  def file_entry(ref, identifier, _path)
99
102
  out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
100
103
  ret = if ref["fileref"]
@@ -122,6 +125,15 @@ module Metanorma
122
125
  Metanorma::Utils::anchor_attributes.each do |(tag_name, attribute_name)|
123
126
  add_suffix_to_attributes(doc, document_suffix, tag_name, attribute_name)
124
127
  end
128
+ url_in_css_styles(doc, document_suffix)
129
+ end
130
+
131
+ # update relative URLs, url(#...), in CSS in @style attrs (including SVG)
132
+ def url_in_css_styles(doc, document_suffix)
133
+ doc.xpath("//*[@style]").each do |s|
134
+ s["style"] = s["style"]
135
+ .gsub(%r{url\(#([^)]+)\)}, "url(#\\1_#{document_suffix})")
136
+ end
125
137
  end
126
138
 
127
139
  # return file contents + output filename for each file in the collection,
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "isodoc"
4
+ require "htmlentities"
4
5
  require_relative "collection_fileprocess"
5
6
  require_relative "fontist_utils"
6
7
  require_relative "util"
@@ -35,7 +36,7 @@ module Metanorma
35
36
 
36
37
  @isodoc = isodoc_create # output processor for flavour
37
38
  @outdir = dir_name_cleanse(options[:output_folder])
38
- @coverpage = options[:coverpage]
39
+ @coverpage = options[:coverpage] || collection.coverpage
39
40
  @format = Util.sort_extensions_execution(options[:format])
40
41
  @compile_options = options[:compile] || {}
41
42
  @compile_options[:no_install_fonts] = true if options[:no_install_fonts]
@@ -45,6 +46,7 @@ module Metanorma
45
46
  @directives = collection.directives
46
47
  @disambig = Util::DisambigFiles.new
47
48
  @compile = Compile.new
49
+ @c = HTMLEntities.new
48
50
 
49
51
  # list of files in the collection
50
52
  @files = read_files folder
@@ -97,7 +99,8 @@ module Metanorma
97
99
 
98
100
  def concatenate1(out, ext)
99
101
  out.directives << "documents-inline"
100
- out.bibdatas.each_key do |id|
102
+ out.bibdatas.each_key do |ident|
103
+ id = @c.decode(@isodoc.docid_prefix(nil, ident.dup))
101
104
  @files[id][:attachment] || @files[id][:outputs].nil? and next
102
105
 
103
106
  out.documents[id] =
@@ -148,7 +151,8 @@ module Metanorma
148
151
  isodoc.meta.set(:navigation, indexfile(@xml.at(ns("//manifest"))))
149
152
  isodoc.meta.set(:docrefs, liquid_docrefs)
150
153
  isodoc.meta.set(:"prefatory-content",
151
- isodoc_builder(isodoc, @xml.at(ns("//prefatory-content"))))
154
+ isodoc_builder(isodoc,
155
+ @xml.at(ns("//prefatory-content"))))
152
156
  isodoc.meta.set(:"final-content",
153
157
  isodoc_builder(isodoc, @xml.at(ns("//final-content"))))
154
158
  isodoc.info(@xml, nil)
@@ -156,7 +160,7 @@ module Metanorma
156
160
  end
157
161
 
158
162
  def isodoc_builder(isodoc, node)
159
- Nokogiri::HTML::Builder.new do |b|
163
+ Nokogiri::HTML::Builder.new(encoding: "UTF-8") do |b|
160
164
  b.div do |div|
161
165
  node&.children&.each { |n| isodoc.parse(n, div) }
162
166
  end
@@ -212,9 +216,12 @@ module Metanorma
212
216
  def docrefs(elm, builder)
213
217
  elm.xpath(ns("./docref[@index = 'true']")).each do |d|
214
218
  ident = d.at(ns("./identifier")).children.to_xml
219
+ ident = @c.decode(@isodoc.docid_prefix(nil, ident))
215
220
  builder.li do |li|
216
221
  li.a href: index_link(d, ident) do |a|
217
- a << ident
222
+ a << ident.split(/([<>&])/).map do |x|
223
+ /[<>&]/.match?(x) ? x : @c.encode(x, :hexadecimal)
224
+ end.join
218
225
  end
219
226
  end
220
227
  end
@@ -250,6 +257,7 @@ module Metanorma
250
257
  def liquid_docrefs
251
258
  @xml.xpath(ns("//docref[@index = 'true']")).each_with_object([]) do |d, m|
252
259
  ident = d.at(ns("./identifier")).children.to_xml
260
+ ident = @c.decode(@isodoc.docid_prefix(nil, ident))
253
261
  title = d.at(ns("./bibdata/title[@type = 'main']")) ||
254
262
  d.at(ns("./bibdata/title")) || d.at(ns("./title"))
255
263
  m << { "identifier" => ident, "file" => index_link(d, ident),
@@ -47,10 +47,27 @@ module Metanorma
47
47
 
48
48
  private
49
49
 
50
+ def mn2relaton_parser(tag)
51
+ case tag.sub(/-standard/, "")
52
+ when "bipm" then RelatonBipm::XMLParser
53
+ when "bsi" then RelatonBsi::XMLParser
54
+ when "ietf" then RelatonIetf::XMLParser
55
+ when "iho" then RelatonIho::XMLParser
56
+ when "itu" then RelatonItu::XMLParser
57
+ when "iec" then RelatonIec::XMLParser
58
+ when "iso" then RelatonIsoBib::XMLParser
59
+ when "nist" then RelatonNist::XMLParser
60
+ when "ogc" then RelatonOgc::XMLParser
61
+ else RelatonBib::XMLParser
62
+ end
63
+ end
64
+
50
65
  # #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
51
66
  # @return [RelatonBib::BibliographicItem,RelatonIso::IsoBibliographicItem]
52
67
  def from_xml(xml)
53
- Relaton::Cli.parse_xml xml.at("//xmlns:bibitem|//xmlns:bibdata")
68
+ b = xml.at("//xmlns:bibitem|//xmlns:bibdata")
69
+ r = mn2relaton_parser(xml.root.name)
70
+ r.from_xml(b.to_xml)
54
71
  end
55
72
 
56
73
  # @param file [String]
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.5.6".freeze
2
+ VERSION = "1.5.7".freeze
3
3
  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.5.6
4
+ version: 1.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor