metanorma 1.5.5 → 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: 6b89c521393022873c1869075ea123a814f157c5bf37cbd4f8b9f34076396a0e
4
- data.tar.gz: b289b1718e6b24dd672ec758210ac483370b5fd56d583d8e6c7d06d3bfceca9d
3
+ metadata.gz: 5a628508e5ba0e2e1d2ec4b77aa35866e67990ca67b38e34278e877b6e2ebee2
4
+ data.tar.gz: c6022674620272b5de0111fe182781b8d18d01bceb38c99b0eae92ad3a1265b6
5
5
  SHA512:
6
- metadata.gz: e914e35240ed44db0d6b822d83e9bfca1fb0573c37b054ba0f343df5378364a41c3f1f7f37634b5cc592111eea696128909c2c2f78667ba96da8ea86fea3f1d4
7
- data.tar.gz: a74dedfd28fb9281a729a26de8c020d560cbc298ec23172db5d6425298094f085a79ee08c76d67da7af3f1b524eb20001f9e5b9e16b63e2c286fb041e0124edd
6
+ metadata.gz: e8dbe50e863d2ae58969dcccb4302425b2f1acca6a3200f3395b069bace35d57376d7b3fc054e99573f6cf4da8ff21539eb233ae6163b85894169247dd010634
7
+ data.tar.gz: 2590266e459d6f211470f5a6f3f282e78e06c5728780871ccf24e2c5069871c9c49fb37d32286cca6218f85ea21435e8c8b40437e07aca8cc2de673e65a71649
@@ -17,9 +17,9 @@ module Metanorma
17
17
  attr_accessor :directives
18
18
 
19
19
  # @return [Hash<String, Metanorma::Document>]
20
- attr_accessor :documents
20
+ attr_accessor :documents, :bibdatas, :coverpage
21
21
 
22
- attr_accessor :disambig
22
+ attr_accessor :disambig, :manifest
23
23
 
24
24
  # @param file [String] path to source file
25
25
  # @param directives [Array<String>] documents-inline to inject the XML into
@@ -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,11 +37,17 @@ 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] || {}
45
+ @bibdatas = args[:documents] || {}
40
46
  if @documents.any? && !@directives.include?("documents-inline")
41
47
  @directives << "documents-inline"
42
48
  end
43
49
  @documents.merge! @manifest.documents(File.dirname(@file))
50
+ @bibdatas.merge! @manifest.documents(File.dirname(@file))
44
51
  @prefatory = args[:prefatory]
45
52
  @final = args[:final]
46
53
  @log = Metanorma::Utils::Log.new
@@ -66,12 +73,29 @@ module Metanorma
66
73
 
67
74
  def collection_body(coll)
68
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
69
79
  @manifest.to_xml coll
70
80
  content_to_xml "prefatory", coll
71
81
  doccontainer coll
72
82
  content_to_xml "final", coll
73
83
  end
74
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
+
75
99
  def render(opts)
76
100
  CollectionRenderer.render self, opts.merge(log: @log)
77
101
  clean_exit
@@ -98,8 +122,27 @@ module Metanorma
98
122
  mnf = CollectionManifest.from_xml mnf_xml
99
123
  pref = pref_final_content xml.at("//xmlns:prefatory-content")
100
124
  fnl = pref_final_content xml.at("//xmlns:final-content")
125
+ cov = pref_final_content xml.at("//xmlns:coverpage")
101
126
  new(file: file, bibdata: bd, manifest: mnf,
102
- documents: docs_from_xml(xml, mnf), prefatory: pref, final: fnl)
127
+ directives: directives_from_xml(xml.xpath("//xmlns:directives")),
128
+ documents: docs_from_xml(xml, mnf),
129
+ bibdatas: docs_from_xml(xml, mnf),
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
103
146
  end
104
147
 
105
148
  def parse_yaml(file)
@@ -135,8 +178,8 @@ module Metanorma
135
178
 
136
179
  <<~CONT
137
180
 
138
- == #{xml.at('title')&.text}
139
- #{xml.at('p')&.text}
181
+ == #{xml.at('title')&.text}
182
+ #{xml.at('p')&.text}
140
183
  CONT
141
184
  end
142
185
  end
@@ -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
@@ -64,9 +64,9 @@ module Metanorma
64
64
  end
65
65
 
66
66
  def fail_update_bibitem(docid, identifier)
67
- error = "[metanorma] Cannot find crossreference to document #{docid} "\
67
+ error = "[metanorma] Cannot find crossreference to document #{docid} " \
68
68
  "in document #{identifier}."
69
- @log.add("Cross-References", nil, error)
69
+ @log&.add("Cross-References", nil, error)
70
70
  Util.log(error, :warning)
71
71
  end
72
72
 
@@ -101,7 +101,7 @@ module Metanorma
101
101
  end
102
102
 
103
103
  def hide_refs(docxml)
104
- docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or "\
104
+ docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or " \
105
105
  "@hidden = 'false'])]")).each do |f|
106
106
  f["hidden"] = "true"
107
107
  end
@@ -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|
@@ -189,7 +195,7 @@ module Metanorma
189
195
  a.children = "#{a.text}_#{Metanorma::Utils::to_ncname(file)}"
190
196
  end
191
197
  end
192
- docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/"\
198
+ docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/" \
193
199
  "docidentifier[@type = 'repository']")) or return
194
200
  docid.children = "current-metanorma-collection/#{file}"
195
201
  docid.previous = "<docidentifier type='X'>#{file}</docidentifier>"
@@ -201,7 +207,7 @@ module Metanorma
201
207
  docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
202
208
  if @files[docid] then update_anchor_loc(bib, e, docid)
203
209
  else
204
- e << "<strong>** Unresolved reference to document #{docid} "\
210
+ e << "<strong>** Unresolved reference to document #{docid} " \
205
211
  "from eref</strong>"
206
212
  end
207
213
  end
@@ -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
@@ -228,18 +234,17 @@ module Metanorma
228
234
  type = "clause" if type == "annex"
229
235
  ref = ins.at(ns("./locality/referenceFrom"))&.text
230
236
  anchor = @files[docid][:anchors].dig(type, ref) or return
231
- ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}"\
237
+ ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}" \
232
238
  "</referenceFrom></locality>"
233
239
  end
234
240
 
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
- .xpath(ns("//bibitem[@type = 'internal']/"\
247
+ .xpath(ns("//bibitem[@type = 'internal']/" \
243
248
  "docidentifier[@type = 'repository']")).each do |d|
244
249
  a = d.text.split(%r{/}, 2)
245
250
  a.size > 1 or next
@@ -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,
@@ -111,6 +111,9 @@ module Metanorma
111
111
  b.identifier do |i|
112
112
  i << dr["identifier"]
113
113
  end
114
+ !dr["attachment"] && !dr["sectionsplit"] &&
115
+ d = @collection.bibdatas[dr["identifier"]] and
116
+ b.parent.add_child(d.bibitem.to_xml(bibdata: true))
114
117
  end
115
118
  docref_to_xml_attrs(drf, dr)
116
119
  end
@@ -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"
@@ -10,6 +11,8 @@ module Metanorma
10
11
  class CollectionRenderer
11
12
  FORMATS = %i[html xml doc pdf].freeze
12
13
 
14
+ attr_accessor :isodoc
15
+
13
16
  # This is only going to render the HTML collection
14
17
  # @param xml [Metanorma::Collection] input XML collection
15
18
  # @param folder [String] input folder
@@ -31,23 +34,23 @@ module Metanorma
31
34
  @doctype = doctype
32
35
  require "metanorma-#{@doctype}"
33
36
 
34
- # output processor for flavour
35
- @isodoc = isodoc
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]
42
43
  @log = options[:log]
43
44
  @documents = collection.documents
45
+ @bibdata = collection.documents
44
46
  @directives = collection.directives
45
47
  @disambig = Util::DisambigFiles.new
46
48
  @compile = Compile.new
49
+ @c = HTMLEntities.new
47
50
 
48
51
  # list of files in the collection
49
52
  @files = read_files folder
50
- isodoc_populate(@isodoc)
53
+ @isodoc = isodoc_populate # output processor for flavour
51
54
  create_non_existing_directory(@outdir)
52
55
  end
53
56
 
@@ -77,6 +80,7 @@ module Metanorma
77
80
  warn "\n\n\n\n\nCoverpage: #{DateTime.now.strftime('%H:%M:%S')}"
78
81
  cr.coverpage if options[:format]&.include?(:html)
79
82
  warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
83
+ cr
80
84
  end
81
85
 
82
86
  def concatenate(col, options)
@@ -95,7 +99,8 @@ module Metanorma
95
99
 
96
100
  def concatenate1(out, ext)
97
101
  out.directives << "documents-inline"
98
- out.documents.each_key do |id|
102
+ out.bibdatas.each_key do |ident|
103
+ id = @c.decode(@isodoc.docid_prefix(nil, ident.dup))
99
104
  @files[id][:attachment] || @files[id][:outputs].nil? and next
100
105
 
101
106
  out.documents[id] =
@@ -125,34 +130,43 @@ module Metanorma
125
130
  end
126
131
  end
127
132
 
128
- # Dummy class
129
133
  class Dummy
130
134
  def attr(_key); end
131
135
  end
132
136
 
133
- # The isodoc class for the metanorma flavour we are using
134
- def isodoc
137
+ def isodoc_create
135
138
  x = Asciidoctor.load nil, backend: @doctype.to_sym
136
- isodoc = x.converter.html_converter(Dummy.new)
139
+ isodoc = x.converter.html_converter(Dummy.new) # to obtain Isodoc class
137
140
  isodoc.i18n_init(@lang, @script, @locale) # read in internationalisation
138
141
  isodoc.metadata_init(@lang, @script, @locale, isodoc.i18n)
139
142
  isodoc.info(@xml, nil)
140
143
  isodoc
141
144
  end
142
145
 
143
- def isodoc_populate(isodoc)
144
- # create the @meta class of isodoc, with "navigation" set to the index bar
146
+ def isodoc_populate
147
+ # create the @meta class of isodoc, for populating Liquid,
148
+ # with "navigation" set to the index bar.
145
149
  # extracted from the manifest
146
- nav = indexfile(@xml.at(ns("//manifest")))
147
- i18n = isodoc.i18n
148
- i18n.set("navigation", nav)
149
- isodoc.metadata_init(@lang, @script, @locale, i18n)
150
- # populate the @meta class of isodoc with the various metadata fields
151
- # native to the flavour; used to populate Liquid
150
+ isodoc = isodoc_create
151
+ isodoc.meta.set(:navigation, indexfile(@xml.at(ns("//manifest"))))
152
+ isodoc.meta.set(:docrefs, liquid_docrefs)
153
+ isodoc.meta.set(:"prefatory-content",
154
+ isodoc_builder(isodoc,
155
+ @xml.at(ns("//prefatory-content"))))
156
+ isodoc.meta.set(:"final-content",
157
+ isodoc_builder(isodoc, @xml.at(ns("//final-content"))))
152
158
  isodoc.info(@xml, nil)
153
159
  isodoc
154
160
  end
155
161
 
162
+ def isodoc_builder(isodoc, node)
163
+ Nokogiri::HTML::Builder.new(encoding: "UTF-8") do |b|
164
+ b.div do |div|
165
+ node&.children&.each { |n| isodoc.parse(n, div) }
166
+ end
167
+ end.doc.root.to_html
168
+ end
169
+
156
170
  # infer the flavour from the first document identifier; relaton does that
157
171
  def doctype
158
172
  if (docid = @xml.at(ns("//bibdata/docidentifier/@type"))&.text)
@@ -172,8 +186,7 @@ module Metanorma
172
186
  # populate liquid template of ARGV[1] with metadata extracted from
173
187
  # collection manifest
174
188
  def coverpage
175
- return unless @coverpage
176
-
189
+ @coverpage or return
177
190
  File.open(File.join(@outdir, "index.html"), "w:UTF-8") do |f|
178
191
  f.write @isodoc.populate_template(File.read(@coverpage))
179
192
  end
@@ -203,9 +216,12 @@ module Metanorma
203
216
  def docrefs(elm, builder)
204
217
  elm.xpath(ns("./docref[@index = 'true']")).each do |d|
205
218
  ident = d.at(ns("./identifier")).children.to_xml
219
+ ident = @c.decode(@isodoc.docid_prefix(nil, ident))
206
220
  builder.li do |li|
207
- li.a **{ href: index_link(d, ident) } do |a|
208
- a << ident
221
+ li.a href: index_link(d, ident) do |a|
222
+ a << ident.split(/([<>&])/).map do |x|
223
+ /[<>&]/.match?(x) ? x : @c.encode(x, :hexadecimal)
224
+ end.join
209
225
  end
210
226
  end
211
227
  end
@@ -238,12 +254,23 @@ module Metanorma
238
254
  end.doc.root.to_html
239
255
  end
240
256
 
257
+ def liquid_docrefs
258
+ @xml.xpath(ns("//docref[@index = 'true']")).each_with_object([]) do |d, m|
259
+ ident = d.at(ns("./identifier")).children.to_xml
260
+ ident = @c.decode(@isodoc.docid_prefix(nil, ident))
261
+ title = d.at(ns("./bibdata/title[@type = 'main']")) ||
262
+ d.at(ns("./bibdata/title")) || d.at(ns("./title"))
263
+ m << { "identifier" => ident, "file" => index_link(d, ident),
264
+ "title" => title&.children&.to_xml,
265
+ "level" => d.at(ns("./level"))&.text }
266
+ end
267
+ end
268
+
241
269
  private
242
270
 
243
271
  def create_non_existing_directory(output_directory)
244
- if !File.exist?(output_directory)
272
+ !File.exist?(output_directory) and
245
273
  FileUtils.mkdir_p(output_directory)
246
- end
247
274
  end
248
275
 
249
276
  def format_sort(formats)
@@ -257,9 +284,8 @@ module Metanorma
257
284
  # @param options [Hash]
258
285
  # @raise [ArgumentError]
259
286
  def check_options(options)
260
- unless options[:format].is_a?(Array) && (FORMATS & options[:format]).any?
287
+ (options[:format].is_a?(Array) && (FORMATS & options[:format]).any?) or
261
288
  raise ArgumentError, "Need to specify formats (xml,html,pdf,doc)"
262
- end
263
289
  end
264
290
  end
265
291
  end
@@ -55,7 +55,8 @@ module Metanorma
55
55
  file.sub!(/^(=[^\n]+\n)/, "\\1:mn-keep-asciimath:\n")
56
56
  dir = File.dirname(filename)
57
57
  dir != "." and
58
- file.gsub!(/^include::/, "include::#{dir}/")
58
+ file = file.gsub(/^include::/, "include::#{dir}/")
59
+ .gsub(/^embed::/, "embed::#{dir}/")
59
60
  [file, @processor.input_to_isodoc(file, filename, options)]
60
61
  end
61
62
 
@@ -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]
@@ -104,7 +121,8 @@ module Metanorma
104
121
 
105
122
  def render_xml(builder)
106
123
  if @raw
107
- builder << @bibitem.root.to_xml
124
+ #builder << @bibitem.root.to_xml
125
+ builder.parent.add_child(@bibitem.root)
108
126
  else
109
127
  builder.send("#{type}-standard") do |b|
110
128
  b << @bibitem.to_xml(bibdata: true)
@@ -36,18 +36,18 @@ module Metanorma
36
36
 
37
37
  def extract_metanorma_options(file)
38
38
  headerextract = file.sub(/\n\n.*$/m, "\n")
39
- /\n:mn-document-class: (?<type>[^\n]+)\n/ =~ headerextract
40
- /\n:mn-output-extensions: (?<extensions>[^\n]+)\n/ =~ headerextract
41
- /\n:mn-relaton-output-file: (?<relaton>[^\n]+)\n/ =~ headerextract
39
+ /\n:mn-document-class:\s+(?<type>[^\n]+)\n/ =~ headerextract
40
+ /\n:mn-output-extensions:\s+(?<extensions>[^\n]+)\n/ =~ headerextract
41
+ /\n:mn-relaton-output-file:\s+(?<relaton>[^\n]+)\n/ =~ headerextract
42
42
  /\n(?<asciimath>:mn-keep-asciimath:[^\n]*)\n/ =~ headerextract
43
43
  asciimath = if defined?(asciimath)
44
44
  (!asciimath.nil? && asciimath != ":mn-keep-asciimath: false")
45
45
  end
46
46
  asciimath = nil if asciimath == false
47
47
  {
48
- type: defined?(type) ? type : nil,
49
- extensions: defined?(extensions) ? extensions : nil,
50
- relaton: defined?(relaton) ? relaton : nil,
48
+ type: defined?(type) ? type&.strip : nil,
49
+ extensions: defined?(extensions) ? extensions&.strip : nil,
50
+ relaton: defined?(relaton) ? relaton&.strip : nil,
51
51
  asciimath: asciimath,
52
52
  }.compact
53
53
  end
@@ -70,11 +70,11 @@ module Metanorma
70
70
  pdf-allow-print pdf-allow-print-hq pdf-allow-fill-in-forms
71
71
  fonts font-license-agreement pdf-allow-access-content
72
72
  pdf-encrypt-metadata iso-word-template document-scheme
73
- localize-number iso-word-bg-strip-color modspec-identifier-base
74
- ).freeze
73
+ localize-number iso-word-bg-strip-color modspec-identifier-base).freeze
75
74
 
76
75
  EMPTY_ADOC_OPTIONS_DEFAULT_TRUE =
77
- %w(data-uri-image suppress-asciimath-dup use-xinclude source-highlighter).freeze
76
+ %w(data-uri-image suppress-asciimath-dup use-xinclude
77
+ source-highlighter).freeze
78
78
 
79
79
  EMPTY_ADOC_OPTIONS_DEFAULT_FALSE =
80
80
  %w(hierarchical-assets break-up-urls-in-tables toc-figures
@@ -88,8 +88,8 @@ module Metanorma
88
88
  def extract_options(file)
89
89
  header = file.sub(/\n\n.*$/m, "\n")
90
90
  ret = ADOC_OPTIONS.each_with_object({}) do |w, acc|
91
- m = /\n:#{w}: ([^\n]+)\n/.match(header) or next
92
- acc[attr_name_normalise(w)] = m[1]
91
+ m = /\n:#{w}:\s+([^\n]+)\n/.match(header) or next
92
+ acc[attr_name_normalise(w)] = m[1]&.strip
93
93
  end
94
94
  ret2 = EMPTY_ADOC_OPTIONS_DEFAULT_TRUE.each_with_object({}) do |w, acc|
95
95
  m = /\n:#{w}:([^\n]*)\n/.match(header) || [nil, "true"]
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.5.5".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.5
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-01-24 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