metanorma 1.5.5 → 1.5.6

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: 6b89c521393022873c1869075ea123a814f157c5bf37cbd4f8b9f34076396a0e
4
- data.tar.gz: b289b1718e6b24dd672ec758210ac483370b5fd56d583d8e6c7d06d3bfceca9d
3
+ metadata.gz: 8def7cdd4a8b5e3605736563382599b2d820b2c18e7305d6567c89b667c89d90
4
+ data.tar.gz: 75b2d6a77b20a782ace64f18f112cae4bb5b5643172c4df31e05e3a4eb817f20
5
5
  SHA512:
6
- metadata.gz: e914e35240ed44db0d6b822d83e9bfca1fb0573c37b054ba0f343df5378364a41c3f1f7f37634b5cc592111eea696128909c2c2f78667ba96da8ea86fea3f1d4
7
- data.tar.gz: a74dedfd28fb9281a729a26de8c020d560cbc298ec23172db5d6425298094f085a79ee08c76d67da7af3f1b524eb20001f9e5b9e16b63e2c286fb041e0124edd
6
+ metadata.gz: 5a95ed1b168dc0a1ce689a2d169f8664fdb087b35332f645836072ee3e13b8be63513ba585210c2f8f5e69d70161b3b1036dc34cc77a0659f14340caaf22d2e4
7
+ data.tar.gz: 2cab73d708c92443edb99dcb7d761169de3fda2dca2fb40e364f374d085e34c1c7cc317ba3f192bbb98309c699719f97fc10552143c235642a610941189580a5
@@ -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
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
@@ -37,10 +37,12 @@ module Metanorma
37
37
  @manifest = args[:manifest]
38
38
  @manifest.collection = self
39
39
  @documents = args[:documents] || {}
40
+ @bibdatas = args[:documents] || {}
40
41
  if @documents.any? && !@directives.include?("documents-inline")
41
42
  @directives << "documents-inline"
42
43
  end
43
44
  @documents.merge! @manifest.documents(File.dirname(@file))
45
+ @bibdatas.merge! @manifest.documents(File.dirname(@file))
44
46
  @prefatory = args[:prefatory]
45
47
  @final = args[:final]
46
48
  @log = Metanorma::Utils::Log.new
@@ -99,7 +101,9 @@ module Metanorma
99
101
  pref = pref_final_content xml.at("//xmlns:prefatory-content")
100
102
  fnl = pref_final_content xml.at("//xmlns:final-content")
101
103
  new(file: file, bibdata: bd, manifest: mnf,
102
- documents: docs_from_xml(xml, mnf), prefatory: pref, final: fnl)
104
+ documents: docs_from_xml(xml, mnf),
105
+ bibdatas: docs_from_xml(xml, mnf),
106
+ prefatory: pref, final: fnl)
103
107
  end
104
108
 
105
109
  def parse_yaml(file)
@@ -135,8 +139,8 @@ module Metanorma
135
139
 
136
140
  <<~CONT
137
141
 
138
- == #{xml.at('title')&.text}
139
- #{xml.at('p')&.text}
142
+ == #{xml.at('title')&.text}
143
+ #{xml.at('p')&.text}
140
144
  CONT
141
145
  end
142
146
  end
@@ -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
@@ -114,7 +114,7 @@ module Metanorma
114
114
  b.xpath(ns("./docidentifier")).each do |d|
115
115
  next unless @files[d.text]
116
116
 
117
- d.next = "<docidentifier type='repository'>"\
117
+ d.next = "<docidentifier type='repository'>" \
118
118
  "current-metanorma-collection/#{d.text}"
119
119
  end
120
120
  end
@@ -189,7 +189,7 @@ module Metanorma
189
189
  a.children = "#{a.text}_#{Metanorma::Utils::to_ncname(file)}"
190
190
  end
191
191
  end
192
- docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/"\
192
+ docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/" \
193
193
  "docidentifier[@type = 'repository']")) or return
194
194
  docid.children = "current-metanorma-collection/#{file}"
195
195
  docid.previous = "<docidentifier type='X'>#{file}</docidentifier>"
@@ -201,7 +201,7 @@ module Metanorma
201
201
  docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
202
202
  if @files[docid] then update_anchor_loc(bib, e, docid)
203
203
  else
204
- e << "<strong>** Unresolved reference to document #{docid} "\
204
+ e << "<strong>** Unresolved reference to document #{docid} " \
205
205
  "from eref</strong>"
206
206
  end
207
207
  end
@@ -228,7 +228,7 @@ module Metanorma
228
228
  type = "clause" if type == "annex"
229
229
  ref = ins.at(ns("./locality/referenceFrom"))&.text
230
230
  anchor = @files[docid][:anchors].dig(type, ref) or return
231
- ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}"\
231
+ ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}" \
232
232
  "</referenceFrom></locality>"
233
233
  end
234
234
 
@@ -239,7 +239,7 @@ module Metanorma
239
239
 
240
240
  file, = targetfile(x, read: true)
241
241
  Nokogiri::XML(file)
242
- .xpath(ns("//bibitem[@type = 'internal']/"\
242
+ .xpath(ns("//bibitem[@type = 'internal']/" \
243
243
  "docidentifier[@type = 'repository']")).each do |d|
244
244
  a = d.text.split(%r{/}, 2)
245
245
  a.size > 1 or next
@@ -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
@@ -10,6 +10,8 @@ module Metanorma
10
10
  class CollectionRenderer
11
11
  FORMATS = %i[html xml doc pdf].freeze
12
12
 
13
+ attr_accessor :isodoc
14
+
13
15
  # This is only going to render the HTML collection
14
16
  # @param xml [Metanorma::Collection] input XML collection
15
17
  # @param folder [String] input folder
@@ -31,9 +33,7 @@ module Metanorma
31
33
  @doctype = doctype
32
34
  require "metanorma-#{@doctype}"
33
35
 
34
- # output processor for flavour
35
- @isodoc = isodoc
36
-
36
+ @isodoc = isodoc_create # output processor for flavour
37
37
  @outdir = dir_name_cleanse(options[:output_folder])
38
38
  @coverpage = options[:coverpage]
39
39
  @format = Util.sort_extensions_execution(options[:format])
@@ -41,13 +41,14 @@ module Metanorma
41
41
  @compile_options[:no_install_fonts] = true if options[:no_install_fonts]
42
42
  @log = options[:log]
43
43
  @documents = collection.documents
44
+ @bibdata = collection.documents
44
45
  @directives = collection.directives
45
46
  @disambig = Util::DisambigFiles.new
46
47
  @compile = Compile.new
47
48
 
48
49
  # list of files in the collection
49
50
  @files = read_files folder
50
- isodoc_populate(@isodoc)
51
+ @isodoc = isodoc_populate # output processor for flavour
51
52
  create_non_existing_directory(@outdir)
52
53
  end
53
54
 
@@ -77,6 +78,7 @@ module Metanorma
77
78
  warn "\n\n\n\n\nCoverpage: #{DateTime.now.strftime('%H:%M:%S')}"
78
79
  cr.coverpage if options[:format]&.include?(:html)
79
80
  warn "\n\n\n\n\nDone: #{DateTime.now.strftime('%H:%M:%S')}"
81
+ cr
80
82
  end
81
83
 
82
84
  def concatenate(col, options)
@@ -95,7 +97,7 @@ module Metanorma
95
97
 
96
98
  def concatenate1(out, ext)
97
99
  out.directives << "documents-inline"
98
- out.documents.each_key do |id|
100
+ out.bibdatas.each_key do |id|
99
101
  @files[id][:attachment] || @files[id][:outputs].nil? and next
100
102
 
101
103
  out.documents[id] =
@@ -125,34 +127,42 @@ module Metanorma
125
127
  end
126
128
  end
127
129
 
128
- # Dummy class
129
130
  class Dummy
130
131
  def attr(_key); end
131
132
  end
132
133
 
133
- # The isodoc class for the metanorma flavour we are using
134
- def isodoc
134
+ def isodoc_create
135
135
  x = Asciidoctor.load nil, backend: @doctype.to_sym
136
- isodoc = x.converter.html_converter(Dummy.new)
136
+ isodoc = x.converter.html_converter(Dummy.new) # to obtain Isodoc class
137
137
  isodoc.i18n_init(@lang, @script, @locale) # read in internationalisation
138
138
  isodoc.metadata_init(@lang, @script, @locale, isodoc.i18n)
139
139
  isodoc.info(@xml, nil)
140
140
  isodoc
141
141
  end
142
142
 
143
- def isodoc_populate(isodoc)
144
- # create the @meta class of isodoc, with "navigation" set to the index bar
143
+ def isodoc_populate
144
+ # create the @meta class of isodoc, for populating Liquid,
145
+ # with "navigation" set to the index bar.
145
146
  # 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
147
+ isodoc = isodoc_create
148
+ isodoc.meta.set(:navigation, indexfile(@xml.at(ns("//manifest"))))
149
+ isodoc.meta.set(:docrefs, liquid_docrefs)
150
+ isodoc.meta.set(:"prefatory-content",
151
+ isodoc_builder(isodoc, @xml.at(ns("//prefatory-content"))))
152
+ isodoc.meta.set(:"final-content",
153
+ isodoc_builder(isodoc, @xml.at(ns("//final-content"))))
152
154
  isodoc.info(@xml, nil)
153
155
  isodoc
154
156
  end
155
157
 
158
+ def isodoc_builder(isodoc, node)
159
+ Nokogiri::HTML::Builder.new do |b|
160
+ b.div do |div|
161
+ node&.children&.each { |n| isodoc.parse(n, div) }
162
+ end
163
+ end.doc.root.to_html
164
+ end
165
+
156
166
  # infer the flavour from the first document identifier; relaton does that
157
167
  def doctype
158
168
  if (docid = @xml.at(ns("//bibdata/docidentifier/@type"))&.text)
@@ -172,8 +182,7 @@ module Metanorma
172
182
  # populate liquid template of ARGV[1] with metadata extracted from
173
183
  # collection manifest
174
184
  def coverpage
175
- return unless @coverpage
176
-
185
+ @coverpage or return
177
186
  File.open(File.join(@outdir, "index.html"), "w:UTF-8") do |f|
178
187
  f.write @isodoc.populate_template(File.read(@coverpage))
179
188
  end
@@ -204,7 +213,7 @@ module Metanorma
204
213
  elm.xpath(ns("./docref[@index = 'true']")).each do |d|
205
214
  ident = d.at(ns("./identifier")).children.to_xml
206
215
  builder.li do |li|
207
- li.a **{ href: index_link(d, ident) } do |a|
216
+ li.a href: index_link(d, ident) do |a|
208
217
  a << ident
209
218
  end
210
219
  end
@@ -238,12 +247,22 @@ module Metanorma
238
247
  end.doc.root.to_html
239
248
  end
240
249
 
250
+ def liquid_docrefs
251
+ @xml.xpath(ns("//docref[@index = 'true']")).each_with_object([]) do |d, m|
252
+ ident = d.at(ns("./identifier")).children.to_xml
253
+ title = d.at(ns("./bibdata/title[@type = 'main']")) ||
254
+ d.at(ns("./bibdata/title")) || d.at(ns("./title"))
255
+ m << { "identifier" => ident, "file" => index_link(d, ident),
256
+ "title" => title&.children&.to_xml,
257
+ "level" => d.at(ns("./level"))&.text }
258
+ end
259
+ end
260
+
241
261
  private
242
262
 
243
263
  def create_non_existing_directory(output_directory)
244
- if !File.exist?(output_directory)
264
+ !File.exist?(output_directory) and
245
265
  FileUtils.mkdir_p(output_directory)
246
- end
247
266
  end
248
267
 
249
268
  def format_sort(formats)
@@ -257,9 +276,8 @@ module Metanorma
257
276
  # @param options [Hash]
258
277
  # @raise [ArgumentError]
259
278
  def check_options(options)
260
- unless options[:format].is_a?(Array) && (FORMATS & options[:format]).any?
279
+ (options[:format].is_a?(Array) && (FORMATS & options[:format]).any?) or
261
280
  raise ArgumentError, "Need to specify formats (xml,html,pdf,doc)"
262
- end
263
281
  end
264
282
  end
265
283
  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
 
@@ -104,7 +104,8 @@ module Metanorma
104
104
 
105
105
  def render_xml(builder)
106
106
  if @raw
107
- builder << @bibitem.root.to_xml
107
+ #builder << @bibitem.root.to_xml
108
+ builder.parent.add_child(@bibitem.root)
108
109
  else
109
110
  builder.send("#{type}-standard") do |b|
110
111
  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.6".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.6
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-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor