metanorma 1.5.12 → 1.6.0

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: 90e1529fc811c113969832dbfd36a70a77d8458259e775ad4967475a95bfdaac
4
- data.tar.gz: 488a0f5e809991464ee2fa0fe9a6bc4cae50795fac9ca0ea7db76139b0dc84ec
3
+ metadata.gz: 9926d7d441baa7f49931673ddc0091763907509e79df809fb2c5c28e14c34d3f
4
+ data.tar.gz: 07c227ddb3b2e1df4077852a48079779ef8fcb94ff9317c24fce9b418d892cca
5
5
  SHA512:
6
- metadata.gz: 911e73b153257019ad46635218dd5d90f0f1ef85cab5e0a3229603727d3ff7c79b88c8c140b24ad5254b94b97622e5ce9cc4e48b8d15e1442330c3c6c05165b6
7
- data.tar.gz: 7c93266f48b1ad6f4bf11a715d9ddcdffdc4b98f910da8ca8c99f55fef412741c40eb2d303e5be92bbfde7b58560b1694f342e1f7026ecac3b1f752e0379ba86
6
+ metadata.gz: 6a35a864a122af1646f7e3fae80019954a629d15209c4f3ab148456f5f5f2cc4a114b0690c08bcfea968661d5a72955d0e02e0a0d07a4e7765539e90fb1bea3d
7
+ data.tar.gz: 2aafcfa732e718ebda4aff3ded2eef29969fe407e8c01cf4e5538072b83f08573b89f4d50740ac67a56a99b4db975672ff3c0ddac49ab15d7febdb62f2690749
@@ -1,6 +1,7 @@
1
1
  module Metanorma
2
2
  # XML collection renderer
3
3
  class CollectionRenderer
4
+ =begin
4
5
  # map locality type and label (e.g. "clause" "1") to id = anchor for
5
6
  # a document
6
7
  # Note: will only key clauses, which have unambiguous reference label in
@@ -35,6 +36,7 @@ module Metanorma
35
36
  filename = "#{id}.html"
36
37
  [file, filename]
37
38
  end
39
+ =end
38
40
 
39
41
  # @param bib [Nokogiri::XML::Element]
40
42
  # @param identifier [String]
@@ -42,8 +44,8 @@ module Metanorma
42
44
  docid = get_bibitem_docid(bib, identifier) or return
43
45
  newbib = dup_bibitem(docid, bib)
44
46
  bib.replace(newbib)
45
- _file, url = targetfile(@files[docid], relative: true, read: false,
46
- doc: !@files[docid][:attachment])
47
+ #_file, url = targetfile(@files[docid], relative: true, read: false, doc: !@files[docid][:attachment])
48
+ _file, url = @files.targetfile_id(docid, relative: true, read: false, doc: !@files.get(docid,:attachment))
47
49
  uri_node = Nokogiri::XML::Node.new "uri", newbib.document
48
50
  uri_node[:type] = "citation"
49
51
  uri_node.content = url
@@ -55,9 +57,11 @@ module Metanorma
55
57
  docid = bib.at(ns("./docidentifier[not(@type)]")) ||
56
58
  bib.at(ns("./docidentifier"))
57
59
  docid &&= @c.decode(@isodoc
58
- .docid_prefix(docid["type"], docid.children.to_xml))
59
- if @files[docid] then docid
60
+ .docid_prefix(docid["type"], docid.children.to_xml)).gsub(/\s/, " ")
61
+ #if @files[docid] then docid
62
+ if @files.get(docid) || @files.get("X #{docid}") then docid
60
63
  else
64
+ #require "debug"; binding.b
61
65
  fail_update_bibitem(docid, identifier)
62
66
  nil
63
67
  end
@@ -71,7 +75,8 @@ module Metanorma
71
75
  end
72
76
 
73
77
  def dup_bibitem(docid, bib)
74
- newbib = @files[docid][:bibdata].dup
78
+ #newbib = @files[docid][:bibdata].dup
79
+ newbib = @files.get(docid,:bibdata).dup
75
80
  newbib.name = "bibitem"
76
81
  newbib["hidden"] = "true"
77
82
  newbib&.at("./*[local-name() = 'ext']")&.remove
@@ -93,7 +98,7 @@ module Metanorma
93
98
  docxml = Nokogiri::XML(file) { |config| config.huge }
94
99
  supply_repo_ids(docxml)
95
100
  update_indirect_refs_to_docs(docxml, internal_refs)
96
- add_document_suffix(identifier, docxml)
101
+ @files.add_document_suffix(identifier, docxml)
97
102
  update_direct_refs_to_docs(docxml, identifier)
98
103
  svgmap_resolve(datauri_encode(docxml))
99
104
  hide_refs(docxml)
@@ -112,9 +117,12 @@ module Metanorma
112
117
  next if b&.at(ns("./docidentifier[@type = 'repository']"))
113
118
 
114
119
  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
120
+ #id = @c.decode(@isodoc
121
+ #.docid_prefix(docid["type"], docid.children.to_xml))
122
+ id = @isodoc
123
+ .docid_prefix(docid["type"], docid.children.to_xml)
124
+ #@files[id] or next
125
+ @files.get(id) or next
118
126
  docid.next = "<docidentifier type='repository'>" \
119
127
  "current-metanorma-collection/#{id}"
120
128
  end
@@ -205,7 +213,8 @@ module Metanorma
205
213
  # disambiguating document suffix on id
206
214
  def update_anchors(bib, docxml, docid) # rubocop:disable Metrics/AbcSize
207
215
  docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
208
- if @files[docid] then update_anchor_loc(bib, e, docid)
216
+ #if @files[docid] then update_anchor_loc(bib, e, docid)
217
+ if @files.get(docid) then update_anchor_loc(bib, e, docid)
209
218
  else
210
219
  e << "<strong>** Unresolved reference to document #{docid} " \
211
220
  "from eref</strong>"
@@ -219,7 +228,8 @@ module Metanorma
219
228
  document_suffix = Metanorma::Utils::to_ncname(docid)
220
229
  ref = loc.at(ns("./referenceFrom")) or return
221
230
  anchor = "#{ref.text}_#{document_suffix}"
222
- return unless @files[docid][:anchors].inject([]) do |m, (_, x)|
231
+ #return unless @files[docid][:anchors].inject([]) do |m, (_, x)|
232
+ return unless @files.get(docid,:anchors).inject([]) do |m, (_, x)|
223
233
  m += x.values
224
234
  end.include?(anchor)
225
235
 
@@ -233,16 +243,20 @@ module Metanorma
233
243
  type = ins.at(ns("./locality/@type"))&.text
234
244
  type = "clause" if type == "annex"
235
245
  ref = ins.at(ns("./locality/referenceFrom"))&.text
236
- anchor = @files[docid][:anchors].dig(type, ref) or return
246
+ #anchor = @files[docid][:anchors].dig(type, ref) or return
247
+ anchor = @files.get(docid,:anchors).dig(type, ref) or return
237
248
  ins << "<locality type='anchor'><referenceFrom>#{anchor.sub(/^_/, '')}" \
238
249
  "</referenceFrom></locality>"
239
250
  end
240
251
 
241
252
  # gather internal bibitem references
242
253
  def gather_internal_refs
243
- @files.each_with_object({}) do |(_, x), refs|
244
- x[:attachment] and next
245
- file, = targetfile(x, read: true)
254
+ #@files.each.with_object({}) do |(_, x), refs|
255
+ @files.keys.each_with_object({}) do |i, refs|
256
+ #x[:attachment] and next
257
+ @files.get(i,:attachment) and next
258
+ #file, = targetfile(x, read: true)
259
+ file, = @files.targetfile_id(i, read: true)
246
260
  Nokogiri::XML(file)
247
261
  .xpath(ns("//bibitem[@type = 'internal']/" \
248
262
  "docidentifier[@type = 'repository']")).each do |d|
@@ -256,10 +270,14 @@ module Metanorma
256
270
 
257
271
  # resolve file location for the target of each internal reference
258
272
  def locate_internal_refs
273
+ #require 'debug'; binding.b
259
274
  refs = gather_internal_refs
260
- @files.keys.reject { |k| @files[k][:attachment] }.each do |identifier|
261
- id = @c.decode(@isodoc.docid_prefix("", identifier.dup))
262
- locate_internal_refs1(refs, identifier, @files[id])
275
+ #@files.keys.reject { |k| @files[k][:attachment] }.each do |identifier|
276
+ @files.keys.reject { |k| @files.get(k,:attachment) }.each do |identifier|
277
+ #id = @c.decode(@isodoc.docid_prefix("", identifier.dup))
278
+ #locate_internal_refs1(refs, identifier, @files[id])
279
+ id = @isodoc.docid_prefix("", identifier.dup)
280
+ locate_internal_refs1(refs, identifier, id)
263
281
  end
264
282
  refs.each do |schema, ids|
265
283
  ids.each do |id, key|
@@ -269,8 +287,10 @@ module Metanorma
269
287
  refs
270
288
  end
271
289
 
272
- def locate_internal_refs1(refs, identifier, filedesc)
273
- file, _filename = targetfile(filedesc, read: true)
290
+ #def locate_internal_refs1(refs, identifier, filedesc)
291
+ def locate_internal_refs1(refs, identifier, ident)
292
+ #file, _filename = targetfile(filedesc, read: true)
293
+ file, _filename = @files.targetfile_id(ident, read: true)
274
294
  xml = Nokogiri::XML(file) { |config| config.huge }
275
295
  t = xml.xpath("//*/@id").each_with_object({}) { |i, x| x[i.text] = true }
276
296
  refs.each do |schema, ids|
@@ -7,6 +7,7 @@ require_relative "collection_fileparse"
7
7
  module Metanorma
8
8
  # XML collection renderer
9
9
  class CollectionRenderer
10
+ =begin
10
11
  # hash for each document in collection of document identifier to:
11
12
  # document reference (fileref or id), type of document reference,
12
13
  # and bibdata entry for that file
@@ -165,51 +166,64 @@ module Metanorma
165
166
  filename.sub!(/\.xml$/, ".html") if doc
166
167
  [file, filename]
167
168
  end
169
+ =end
168
170
 
169
171
  # compile and output individual file in collection
170
172
  # warn "metanorma compile -x html #{f.path}"
171
173
  def file_compile(file, filename, identifier)
172
- return if @files[identifier][:sectionsplit] == "true"
174
+ #return if @files[identifier][:sectionsplit] == "true"
175
+ return if @files.get(identifier,:sectionsplit) == "true"
173
176
 
174
177
  opts = {
175
178
  format: :asciidoc,
176
179
  extension_keys: @format,
177
180
  output_dir: @outdir,
178
- }.merge(compile_options(identifier))
181
+ }.merge(compile_options_update(identifier))
179
182
 
180
183
  @compile.compile file, opts
181
- @files[identifier][:outputs] = {}
184
+ #@files[identifier][:outputs] = {}
185
+ @files.set(identifier,:outputs, {})
182
186
  file_compile_formats(filename, identifier)
183
187
  end
184
188
 
185
- def compile_options(identifier)
189
+ def compile_options_update(identifier)
186
190
  ret = @compile_options.dup
187
191
  Array(@directives).include?("presentation-xml") ||
188
- @files[identifier][:presentationxml] and
192
+ #@files[identifier][:presentationxml] and
193
+ @files.get(identifier,:presentationxml) and
189
194
  ret.merge!(passthrough_presentation_xml: true)
190
- @files[identifier][:sectionsplit] == "true" and
195
+ #@files[identifier][:sectionsplit] == "true" and
196
+ @files.get(identifier,:sectionsplit) == "true" and
191
197
  ret.merge!(sectionsplit: "true")
192
- @files[identifier][:bare] == true and
198
+ #@files[identifier][:bare] == true and
199
+ @files.get(identifier,:bare) == true and
193
200
  ret.merge!(bare: true)
194
201
  ret
195
202
  end
196
203
 
197
204
  def file_compile_formats(filename, identifier)
198
- file_id = @files[identifier]
205
+ #file_id = @files[identifier]
206
+ f = @files.get(identifier, :outputs)
199
207
  @format << :presentation if @format.include?(:pdf)
200
208
  @format.each do |e|
201
209
  ext = @compile.processor.output_formats[e]
202
210
  fn = File.basename(filename).sub(/(?<=\.)[^.]+$/, ext.to_s)
203
- unless /html$/.match?(ext) && file_id[:sectionsplit]
204
- file_id[:outputs][e] = File.join(@outdir, fn)
211
+ #unless /html$/.match?(ext) && file_id[:sectionsplit]
212
+ unless /html$/.match?(ext) && @files.get(identifier, :sectionsplit)
213
+ #file_id[:outputs][e] = File.join(@outdir, fn)
214
+ f[e] = File.join(@outdir, fn)
205
215
  end
206
216
  end
217
+ @files.set(identifier,:outputs, f)
207
218
  end
208
219
 
209
- def copy_file_to_dest(fileref)
210
- dest = File.join(@outdir, fileref[:out_path])
220
+ #def copy_file_to_dest(fileref)
221
+ def copy_file_to_dest(identifier)
222
+ dest = File.join(@outdir, @files.get(identifier,:out_path))
211
223
  FileUtils.mkdir_p(File.dirname(dest))
212
- FileUtils.cp fileref[:ref], dest
224
+ #FileUtils.cp fileref[:ref], dest
225
+ #require "debug"; binding.b
226
+ FileUtils.cp @files.get(identifier,:ref), dest
213
227
  end
214
228
 
215
229
  # process each file in the collection
@@ -217,12 +231,15 @@ module Metanorma
217
231
  def files # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
218
232
  warn "\n\n\n\n\nInternal Refs: #{DateTime.now.strftime('%H:%M:%S')}"
219
233
  internal_refs = locate_internal_refs
220
- @files.each_with_index do |(identifier, x), i|
234
+ #@files.each_with_index do |(identifier, x), i|
235
+ @files.keys.each_with_index do |identifier, i|
221
236
  i.positive? && Array(@directives).include?("bare-after-first") and
222
237
  @compile_options.merge!(bare: true)
223
- if x[:attachment] then copy_file_to_dest(x)
238
+ #if x[:attachment] then copy_file_to_dest(x)
239
+ if @files.get(identifier,:attachment) then copy_file_to_dest(identifier)
224
240
  else
225
- file, filename = targetfile(x, read: true)
241
+ #file, filename = @files.targetfile(x, read: true)
242
+ file, filename = @files.targetfile_id(identifier, read: true)
226
243
  warn "\n\n\n\n\nProcess #{filename}: #{DateTime.now.strftime('%H:%M:%S')}"
227
244
  collection_xml = update_xrefs(file, identifier, internal_refs)
228
245
  collection_filename = File.basename(filename, File.extname(filename))
@@ -5,6 +5,7 @@ require "htmlentities"
5
5
  require_relative "collection_fileprocess"
6
6
  require_relative "fontist_utils"
7
7
  require_relative "util"
8
+ require_relative "files_lookup"
8
9
 
9
10
  module Metanorma
10
11
  # XML collection renderer
@@ -12,6 +13,7 @@ module Metanorma
12
13
  FORMATS = %i[html xml doc pdf].freeze
13
14
 
14
15
  attr_accessor :isodoc
16
+ attr_reader :xml, :compile, :compile_options, :documents
15
17
 
16
18
  # This is only going to render the HTML collection
17
19
  # @param xml [Metanorma::Collection] input XML collection
@@ -49,8 +51,9 @@ module Metanorma
49
51
  @c = HTMLEntities.new
50
52
 
51
53
  # list of files in the collection
52
- @files = read_files folder
53
- @isodoc = isodoc_populate # output processor for flavour
54
+ #@files = read_files folder
55
+ @files = Metanorma::FileLookup.new(folder, self)
56
+ isodoc_populate
54
57
  create_non_existing_directory(@outdir)
55
58
  end
56
59
 
@@ -100,11 +103,14 @@ module Metanorma
100
103
  def concatenate1(out, ext)
101
104
  out.directives << "documents-inline"
102
105
  out.bibdatas.each_key do |ident|
103
- id = @c.decode(@isodoc.docid_prefix(nil, ident.dup))
104
- @files[id][:attachment] || @files[id][:outputs].nil? and next
106
+ #id = @c.decode(@isodoc.docid_prefix(nil, ident.dup))
107
+ #@files[id][:attachment] || @files[id][:outputs].nil? and next
108
+ id = @isodoc.docid_prefix(nil, ident.dup)
109
+ @files.get(id,:attachment) || @files.get(id,:outputs).nil? and next
105
110
 
106
111
  out.documents[id] =
107
- Metanorma::Document.raw_file(@files[id][:outputs][ext])
112
+ #Metanorma::Document.raw_file(@files[id][:outputs][ext])
113
+ Metanorma::Document.raw_file(@files.get(id,:outputs)[ext])
108
114
  end
109
115
  out
110
116
  end
@@ -147,16 +153,14 @@ module Metanorma
147
153
  # create the @meta class of isodoc, for populating Liquid,
148
154
  # with "navigation" set to the index bar.
149
155
  # extracted from the manifest
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,
156
+ @isodoc.meta.set(:navigation, indexfile(@xml.at(ns("//manifest"))))
157
+ @isodoc.meta.set(:docrefs, liquid_docrefs)
158
+ @isodoc.meta.set(:"prefatory-content",
159
+ isodoc_builder(@isodoc,
155
160
  @xml.at(ns("//prefatory-content"))))
156
- isodoc.meta.set(:"final-content",
161
+ @isodoc.meta.set(:"final-content",
157
162
  isodoc_builder(isodoc, @xml.at(ns("//final-content"))))
158
- isodoc.info(@xml, nil)
159
- isodoc
163
+ @isodoc.info(@xml, nil)
160
164
  end
161
165
 
162
166
  def isodoc_builder(isodoc, node)
@@ -229,7 +233,8 @@ module Metanorma
229
233
 
230
234
  def index_link(docref, ident)
231
235
  if docref["fileref"]
232
- @files[ident][:out_path].sub(/\.xml$/, ".html")
236
+ #@files[ident][:out_path].sub(/\.xml$/, ".html")
237
+ @files.get(ident,:out_path).sub(/\.xml$/, ".html")
233
238
  else "#{docref['id']}.html"
234
239
  end
235
240
  end
@@ -0,0 +1,255 @@
1
+ require "isodoc"
2
+ require "htmlentities"
3
+ require "metanorma-utils"
4
+
5
+ module Metanorma
6
+ # XML collection renderer
7
+ class FileLookup
8
+ # hash for each document in collection of document identifier to:
9
+ # document reference (fileref or id), type of document reference,
10
+ # and bibdata entry for that file
11
+ # @param path [String] path to collection
12
+ def initialize(path, parent)
13
+ @c = HTMLEntities.new
14
+ @files = {}
15
+ @parent = parent
16
+ @xml = parent.xml
17
+ @isodoc = parent.isodoc
18
+ @path = path
19
+ @compile = parent.compile
20
+ @documents = parent.documents
21
+ read_files
22
+ end
23
+
24
+ def read_files
25
+ @xml.xpath(ns("//docref")).each { |d| read_file(d) }
26
+ add_section_split
27
+ end
28
+
29
+ def read_file(docref)
30
+ ident = docref.at(ns("./identifier"))
31
+ i = key(@isodoc.docid_prefix(ident["type"], ident.children.to_xml))
32
+ entry = file_entry(docref, ident.children.to_xml)
33
+ bibdata_process(entry, i)
34
+ bibitem_process(entry)
35
+ @files[i] = entry
36
+ end
37
+
38
+ def bibdata_process(entry, identifier)
39
+ if entry[:attachment]
40
+ entry[:bibdata] = Metanorma::Document
41
+ .attachment_bibitem(identifier).root
42
+ else
43
+ file, _filename = targetfile(entry, read: true)
44
+ xml = Nokogiri::XML(file)
45
+ add_document_suffix(identifier, xml)
46
+ entry[:anchors] = read_anchors(xml)
47
+ entry[:bibdata] = xml.at(ns("//bibdata"))
48
+ end
49
+ end
50
+
51
+ def bibitem_process(entry)
52
+ entry[:bibitem] = entry[:bibdata].dup
53
+ entry[:bibitem].name = "bibitem"
54
+ entry[:bibitem]["hidden"] = "true"
55
+ entry[:bibitem].at("./*[local-name() = 'ext']")&.remove
56
+ end
57
+
58
+ def add_section_split
59
+ #require "debug"; binding.b
60
+ ret = @files.keys.each_with_object({}) do |k, m|
61
+ if @files[k][:sectionsplit] == "true" && !@files[k]["attachment"]
62
+ s, manifest = sectionsplit(@files[k][:ref])
63
+ s.each_with_index do |f1, i|
64
+ add_section_split_instance(f1, m, k, i)
65
+ end
66
+ m["#{k}:index.html"] = add_section_split_cover(manifest, k)
67
+ end
68
+ m[k] = @files[k]
69
+ #require "debug"; binding.b
70
+ end
71
+ @files = ret
72
+ end
73
+
74
+ def add_section_split_cover(manifest, ident)
75
+ cover = section_split_cover(manifest, @parent.dir_name_cleanse(ident))
76
+ @files[ident][:out_path] = cover
77
+ { attachment: true, index: false, out_path: cover,
78
+ ref: File.join(File.dirname(manifest.file), cover) }
79
+ end
80
+
81
+ def section_split_cover(col, ident)
82
+ dir = File.dirname(col.file)
83
+ @compile.collection_setup(nil, dir)
84
+ #require "debug";binding.b
85
+ CollectionRenderer.new(col, dir,
86
+ output_folder: "#{ident}_collection",
87
+ format: %i(html),
88
+ coverpage: File.join(dir, "cover.html")).coverpage
89
+ FileUtils.mv "#{ident}_collection/index.html",
90
+ File.join(dir, "#{ident}_index.html")
91
+ FileUtils.rm_rf "#{ident}_collection"
92
+ "#{ident}_index.html"
93
+ end
94
+
95
+ def add_section_split_instance(file, manifest, key, idx)
96
+ presfile = File.join(File.dirname(@files[key][:ref]),
97
+ File.basename(file[:url]))
98
+ newkey = key("#{key.strip} #{file[:title]}")
99
+ manifest[newkey] =
100
+ { parentid: key, presentationxml: true, type: "fileref",
101
+ rel_path: file[:url], out_path: File.basename(file[:url]),
102
+ anchors: read_anchors(Nokogiri::XML(File.read(presfile))),
103
+ bibdata: @files[key][:bibdata], ref: presfile }
104
+ manifest[newkey][:bare] = true unless idx.zero?
105
+ end
106
+
107
+ def sectionsplit(file)
108
+ #require "debug"; binding.b
109
+ @compile.compile(
110
+ file, { format: :asciidoc, extension_keys: [:presentation] }
111
+ .merge(@parent.compile_options)
112
+ )
113
+ r = file.sub(/\.xml$/, ".presentation.xml")
114
+ xml = Nokogiri::XML(File.read(r))
115
+ s = @compile.sectionsplit(xml, File.basename(r), File.dirname(r))
116
+ .sort_by { |f| f[:order] }
117
+ [s, @compile.collection_manifest(File.basename(r), s, xml, nil,
118
+ File.dirname(r))]
119
+ end
120
+
121
+ # rel_path is the source file address, determined relative to the YAML.
122
+ # out_path is the destination file address, with any references outside
123
+ # the working directory (../../...) truncated
124
+ # identifier is the id with only spaces, no nbsp
125
+ def file_entry(ref, identifier)
126
+ out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
127
+ ret = if ref["fileref"]
128
+ { type: "fileref", ref: @documents[identifier].file,
129
+ rel_path: ref["fileref"], out_path: out }
130
+ else { type: "id", ref: ref["id"] } end
131
+ %w(attachment sectionsplit index presentation-xml
132
+ bare-after-first).each do |s|
133
+ ret[s.gsub("-", "").to_sym] = ref[s] if ref[s]
134
+ end
135
+ ret.compact
136
+ end
137
+
138
+ def add_suffix_to_attributes(doc, suffix, tag_name, attribute_name)
139
+ doc.xpath(ns("//#{tag_name}[@#{attribute_name}]")).each do |elem|
140
+ elem.attributes[attribute_name].value =
141
+ "#{elem.attributes[attribute_name].value}_#{suffix}"
142
+ end
143
+ end
144
+
145
+ def add_document_suffix(identifier, doc)
146
+ document_suffix = Metanorma::Utils::to_ncname(identifier)
147
+ Metanorma::Utils::anchor_attributes.each do |(tag_name, attribute_name)|
148
+ add_suffix_to_attributes(doc, document_suffix, tag_name, attribute_name)
149
+ end
150
+ url_in_css_styles(doc, document_suffix)
151
+ end
152
+
153
+ # update relative URLs, url(#...), in CSS in @style attrs (including SVG)
154
+ def url_in_css_styles(doc, document_suffix)
155
+ doc.xpath("//*[@style]").each do |s|
156
+ s["style"] = s["style"]
157
+ .gsub(%r{url\(#([^)]+)\)}, "url(#\\1_#{document_suffix})")
158
+ end
159
+ end
160
+
161
+ # return file contents + output filename for each file in the collection,
162
+ # given a docref entry
163
+ # @param data [Hash] docref entry
164
+ # @param read [Boolean] read the file in and return it
165
+ # @param doc [Boolean] I am a Metanorma document,
166
+ # so my URL should end with html or pdf or whatever
167
+ # @param relative [Boolean] Return output path,
168
+ # formed relative to YAML file, not input path, relative to calling function
169
+ # @return [Array<String, nil>]
170
+ def targetfile(data, options)
171
+ options = { read: false, doc: true, relative: false }.merge(options)
172
+ path = options[:relative] ? data[:rel_path] : data[:ref]
173
+ if data[:type] == "fileref"
174
+ ref_file path, data[:out_path], options[:read], options[:doc]
175
+ else
176
+ xml_file data[:id], options[:read]
177
+ end
178
+ end
179
+
180
+ def targetfile_id(ident, options)
181
+ targetfile(get(ident), options)
182
+ end
183
+
184
+ def ref_file(ref, out, read, doc)
185
+ file = File.read(ref, encoding: "utf-8") if read
186
+ filename = out.dup
187
+ filename.sub!(/\.xml$/, ".html") if doc
188
+ [file, filename]
189
+ end
190
+
191
+ def xml_file(id, read)
192
+ file = @xml.at(ns("//doc-container[@id = '#{id}']")).to_xml if read
193
+ filename = "#{id}.html"
194
+ [file, filename]
195
+ end
196
+
197
+ # map locality type and label (e.g. "clause" "1") to id = anchor for
198
+ # a document
199
+ # Note: will only key clauses, which have unambiguous reference label in
200
+ # locality. Notes, examples etc with containers are just plunked against
201
+ # UUIDs, so that their IDs can at least be registered to be tracked
202
+ # as existing.
203
+ def read_anchors(xml)
204
+ xrefs = @isodoc.xref_init(@lang, @script, @isodoc, @isodoc.i18n,
205
+ { locale: @locale })
206
+ xrefs.parse xml
207
+ xrefs.get.each_with_object({}) do |(k, v), ret|
208
+ read_anchors1(k, v, ret)
209
+ end
210
+ end
211
+
212
+ def read_anchors1(key, val, ret)
213
+ val[:type] ||= "clause"
214
+ ret[val[:type]] ||= {}
215
+ index = if val[:container] || val[:label].nil? || val[:label].empty?
216
+ UUIDTools::UUID.random_create.to_s
217
+ else val[:label]
218
+ end
219
+ ret[val[:type]][index] = key
220
+ ret[val[:type]][val[:value]] = key if val[:value]
221
+ end
222
+
223
+ def key(ident)
224
+ @c.decode(ident).gsub(/(\s|[ ])+/, " ")
225
+ end
226
+
227
+ def keys
228
+ @files.keys
229
+ end
230
+
231
+ def get(ident, attr = nil)
232
+ if attr
233
+ @files[key(ident)][attr]
234
+ else
235
+ @files[key(ident)]
236
+ end
237
+ end
238
+
239
+ def set(ident, attr, value)
240
+ @files[key(ident)][attr] = value
241
+ end
242
+
243
+ def each
244
+ @files.each
245
+ end
246
+
247
+ def each_with_index
248
+ @files.each_with_index
249
+ end
250
+
251
+ def ns(xpath)
252
+ @isodoc.ns(xpath)
253
+ end
254
+ end
255
+ end
@@ -50,7 +50,7 @@ module Metanorma
50
50
  <body>
51
51
  <h1>{{ doctitle }}</h1>
52
52
  <h2>{{ docnumber }}</h2>
53
- <nav>{{ labels["navigation"] }}</nav>
53
+ <nav>{{ navigation }}</nav>
54
54
  </body>
55
55
  </html>
56
56
  COVER
@@ -60,7 +60,7 @@ module Metanorma
60
60
  [["//preface/*", "preface"], ["//sections/*", "sections"],
61
61
  ["//annex", nil],
62
62
  ["//bibliography/*[not(@hidden = 'true')]", "bibliography"],
63
- ["//indexsect", nil]].freeze
63
+ ["//indexsect", nil], ["//colophon", nil]].freeze
64
64
 
65
65
  def sectionsplit(xml, filename, dir)
66
66
  @key = xref_preprocess(xml)
@@ -76,8 +76,9 @@ module Metanorma
76
76
  def emptydoc(xml)
77
77
  out = xml.dup
78
78
  out.xpath(
79
- ns("//preface | //sections | //annex | //bibliography/clause | "\
80
- "//bibliography/references[not(@hidden = 'true')] | //indexsect"),
79
+ ns("//preface | //sections | //annex | //bibliography/clause | " \
80
+ "//bibliography/references[not(@hidden = 'true')] | //indexsect" \
81
+ "//colophon"),
81
82
  ).each(&:remove)
82
83
  out
83
84
  end
@@ -123,7 +124,7 @@ module Metanorma
123
124
  next unless /^#/.match? a["href"]
124
125
 
125
126
  a["href"] = a["href"].sub(/^#/, "")
126
- m << "<target href='#{a['href']}'>"\
127
+ m << "<target href='#{a['href']}'>" \
127
128
  "<xref target='#{a['href']}'/></target>"
128
129
  end
129
130
  end
@@ -137,7 +138,7 @@ module Metanorma
137
138
  end
138
139
 
139
140
  def make_anchor(anchor)
140
- "<localityStack><locality type='anchor'><referenceFrom>"\
141
+ "<localityStack><locality type='anchor'><referenceFrom>" \
141
142
  "#{anchor}</referenceFrom></locality></localityStack>"
142
143
  end
143
144
 
@@ -155,7 +156,7 @@ module Metanorma
155
156
  def eref_to_internal_eref(section, xml, key)
156
157
  eref_to_internal_eref_select(section, xml).each_with_object([]) do |x, m|
157
158
  url = xml.at(ns("//bibitem[@id = '#{x}']/uri[@type = 'citation']"))
158
- section.xpath(("//*[@bibitemid = '#{x}']")).each do |e|
159
+ section.xpath("//*[@bibitemid = '#{x}']").each do |e|
159
160
  id = eref_to_internal_eref1(e, key, url)
160
161
  id and m << id
161
162
  end
@@ -176,10 +177,10 @@ module Metanorma
176
177
  end
177
178
 
178
179
  def eref_to_internal_eref_select(section, xml)
179
- refs = section.xpath(("//*/@bibitemid")).map { |x| x.text } # rubocop:disable Style/SymbolProc
180
+ refs = section.xpath("//*/@bibitemid").map { |x| x.text } # rubocop:disable Style/SymbolProc
180
181
  refs.uniq.reject do |x|
181
182
  xml.at(ns("//bibitem[@id = '#{x}'][@type = 'internal']")) ||
182
- xml.at(ns("//bibitem[@id = '#{x}']"\
183
+ xml.at(ns("//bibitem[@id = '#{x}']" \
183
184
  "[docidentifier/@type = 'repository']"))
184
185
  end
185
186
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.5.12".freeze
2
+ VERSION = "1.6.0".freeze
3
3
  end
data/metanorma.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "asciidoctor"
27
27
  spec.add_runtime_dependency "fontist", ">= 1.14.3"
28
28
  spec.add_runtime_dependency "htmlentities"
29
- spec.add_runtime_dependency "isodoc", ">= 2.5.4"
29
+ spec.add_runtime_dependency "isodoc", ">= 2.6.0"
30
30
  spec.add_runtime_dependency "mn2pdf", "~> 1"
31
31
  spec.add_runtime_dependency "nokogiri"
32
32
  spec.add_runtime_dependency "pry"
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.12
4
+ version: 1.6.0
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-07-24 00:00:00.000000000 Z
11
+ date: 2023-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 2.5.4
61
+ version: 2.6.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 2.5.4
68
+ version: 2.6.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mn2pdf
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +267,7 @@ files:
267
267
  - lib/metanorma/config.rb
268
268
  - lib/metanorma/document.rb
269
269
  - lib/metanorma/extract.rb
270
+ - lib/metanorma/files_lookup.rb
270
271
  - lib/metanorma/fontist_utils.rb
271
272
  - lib/metanorma/input.rb
272
273
  - lib/metanorma/input/asciidoc.rb