metanorma 1.6.4 → 1.6.5

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: abbc191b2e898bbeeea46f7867bb9d25d44cfd7f9a0dd2c690fcbdb8383136fd
4
- data.tar.gz: a9e184662fcf25a575c278d604440b8215fd7b54b76f980a4cf4bfd5f8a1f543
3
+ metadata.gz: e4bbd3fdfd37664da0a7f9e91cbecfcb0f7cdd49c004cf75eaa122c366ea6fba
4
+ data.tar.gz: 6b61241e1010ed465995c23447b4828503495d8f4fb2366e64babe0ae6d0726e
5
5
  SHA512:
6
- metadata.gz: bfc28efd7f7f48f0bfd7dfa630bf88f1186006022dc6d5f82f188a3749304bc73837c9e96dd9246655de67f2b1ee29d9525f49c2ba568e2116d4329bf3689bda
7
- data.tar.gz: 40bc185f4dbe9b4570349e22a15334a2e3fb089dfe3002ab43cb4a8ffa4afe4f2a3ae8357f80e61d585a57ab3b64e24dd5fb2700241dd6f1b958693214afdbc6
6
+ metadata.gz: dc05aa1c9d8aec0e6d45b537e10a130f88e715116f0dd92820e73588ff5a6542a7f2f92099e504654d2ed21e4e95c4bd84c0b260e24f923720b38ae298455f33
7
+ data.tar.gz: 870e182c05914d484180fd19360bfe1010cb9b57ed926926d76ba6cde3d9f2adbf2cb98e5d7e44702f2024cd51b52347524b9fb0ac28c0463d01b3d1dfc9d7b6
@@ -102,7 +102,7 @@ module Metanorma
102
102
  end
103
103
 
104
104
  def svgmap_resolve1(eref, isodoc, _docxml, ids)
105
- href = isodoc.eref_target(eref)
105
+ href = isodoc.eref_target(eref) or return
106
106
  return if href == "##{eref['bibitemid']}" ||
107
107
  (href =~ /^#/ && !ids[href.sub(/^#/, "")])
108
108
 
@@ -119,15 +119,24 @@ module Metanorma
119
119
  def update_direct_refs_to_docs(docxml, identifier)
120
120
  @ncnames = {}
121
121
  erefs = Util::gather_citeases(docxml)
122
+ erefs1 = Util::gather_bibitemids(docxml)
122
123
  docxml.xpath(ns("//bibitem")).each do |b|
123
- docid = b.at(ns("./docidentifier[@type = 'repository']"))
124
- (docid && %r{^current-metanorma-collection/}.match(docid.text)) or next
124
+ docid = b.at(ns("./docidentifier[@type = 'repository']")) or next
125
+ unless %r{^current-metanorma-collection/}.match(docid.text)
126
+ erefs1[b["id"]]&.each { |x| strip_eref(x) }
127
+ next
128
+ end
125
129
  update_bibitem(b, identifier)
126
130
  docid = docid_to_citeas(b) or next
127
131
  erefs[docid] and update_anchors(b, docid, erefs[docid])
128
132
  end
129
133
  end
130
134
 
135
+ def strip_eref(eref)
136
+ eref.xpath(ns("./locality | ./localityStack")).each(&:remove)
137
+ eref.replace(eref.children)
138
+ end
139
+
131
140
  def docid_to_citeas(bib)
132
141
  docid = bib.at(ns("./docidentifier[@primary = 'true']")) ||
133
142
  bib.at(ns("./docidentifier")) or return
@@ -118,7 +118,7 @@ module Metanorma
118
118
  end
119
119
 
120
120
  def docref_to_xml_attrs(elem, docref)
121
- elem[:fileref] = @disambig.source2dest_filename(docref["fileref"])
121
+ elem[:fileref] = @disambig.strip_root(docref["fileref"])
122
122
  %i(attachment sectionsplit).each do |i|
123
123
  elem[i] = docref[i.to_s] if docref[i.to_s]
124
124
  end
@@ -81,25 +81,25 @@ module Metanorma
81
81
  isodoc
82
82
  end
83
83
 
84
+ # create the @meta class of isodoc, for populating Liquid,
85
+ # with "navigation" set to the index bar.
86
+ # extracted from the manifest
84
87
  def isodoc_populate
85
- # create the @meta class of isodoc, for populating Liquid,
86
- # with "navigation" set to the index bar.
87
- # extracted from the manifest
88
- @isodoc.meta.set(:navigation, indexfile(@xml.at(ns("//manifest"))))
89
- @isodoc.meta.set(:docrefs, liquid_docrefs)
90
- @isodoc.meta.set(:"prefatory-content",
91
- isodoc_builder(@isodoc,
92
- @xml.at(ns("//prefatory-content"))))
93
- @isodoc.meta.set(:"final-content",
94
- isodoc_builder(isodoc,
95
- @xml.at(ns("//final-content"))))
96
88
  @isodoc.info(@xml, nil)
89
+ m = @xml.at(ns("//manifest"))
90
+ { navigation: indexfile(m), nav_object: index_object(m),
91
+ docrefs: liquid_docrefs,
92
+ "prefatory-content": isodoc_builder(@xml.at(ns("//prefatory-content"))),
93
+ "final-content": isodoc_builder(@xml.at(ns("//final-content"))),
94
+ doctitle: m.at(ns("../bibdata/title"))&.text,
95
+ docnumber: m.at(ns("../bibdata/docidentifier"))&.text
96
+ }.each { |k, v| v and @isodoc.meta.set(k, v) }
97
97
  end
98
98
 
99
- def isodoc_builder(isodoc, node)
99
+ def isodoc_builder(node)
100
100
  Nokogiri::HTML::Builder.new(encoding: "UTF-8") do |b|
101
101
  b.div do |div|
102
- node&.children&.each { |n| isodoc.parse(n, div) }
102
+ node&.children&.each { |n| @isodoc.parse(n, div) }
103
103
  end
104
104
  end.doc.root.to_html
105
105
  end
@@ -132,9 +132,7 @@ module Metanorma
132
132
  # @param elm [Nokogiri::XML::Element]
133
133
  # @return [String]
134
134
  def indexfile_title(elm)
135
- lvl = elm.at(ns("./level"))&.text&.capitalize
136
- lbl = elm.at(ns("./title"))&.text
137
- "#{lvl}#{lvl && lbl ? ': ' : ''}#{lbl}"
135
+ elm.at(ns("./title"))&.text
138
136
  end
139
137
 
140
138
  # uses the identifier to label documents; other attributes (title) can be
@@ -172,10 +170,6 @@ module Metanorma
172
170
  end
173
171
 
174
172
  # single level navigation list, with hierarchical nesting
175
- # if multiple lists are needed as separate HTML fragments, multiple
176
- # instances of this function will be needed,
177
- # and associated to different variables in the call to @isodoc.metadata_init
178
- # (including possibly an array of HTML fragments)
179
173
  #
180
174
  # @param elm [Nokogiri::XML::Element]
181
175
  # @return [String] XML
@@ -191,6 +185,20 @@ module Metanorma
191
185
  end.doc.root.to_html
192
186
  end
193
187
 
188
+ # object to construct navigation out of in Liquid
189
+ def index_object(elm)
190
+ c = elm.xpath(ns("./manifest")).each_with_object([]) do |d, b|
191
+ b << index_object(d)
192
+ end
193
+ c.empty? and c = nil
194
+ r = Nokogiri::HTML::Builder.new do |b|
195
+ indexfile_docref(elm, b)
196
+ end
197
+ r &&= r.doc.root&.to_html&.gsub("\n", " ")
198
+ { title: indexfile_title(elm),
199
+ docrefs: r, children: c }.compact
200
+ end
201
+
194
202
  def liquid_docrefs
195
203
  @xml.xpath(ns("//docref[@index = 'true']")).each_with_object([]) do |d, m|
196
204
  ident = d.at(ns("./identifier")).children.to_xml
@@ -26,6 +26,7 @@ module Metanorma
26
26
  end
27
27
 
28
28
  def read_files
29
+ @disambig = Util::DisambigFiles.new
29
30
  @xml.xpath(ns("//docref")).each { |d| read_file(d) }
30
31
  end
31
32
 
@@ -65,15 +66,22 @@ module Metanorma
65
66
  # identifier is the id with only spaces, no nbsp
66
67
  def file_entry(ref, identifier)
67
68
  out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
69
+ out1 = @disambig.source2dest_filename(out)
68
70
  ret = if ref["fileref"]
69
71
  { type: "fileref", ref: @documents[identifier].file,
70
- rel_path: ref["fileref"], out_path: out }
71
- else { type: "id", ref: ref["id"] } end
72
+ rel_path: ref["fileref"],
73
+ out_path: out1 } # @disambig.source2dest_filename(out) }
74
+ else { type: "id", ref: ref["id"] }
75
+ end
76
+ file_entry_copy(ref, ret)
77
+ ret.compact
78
+ end
79
+
80
+ def file_entry_copy(ref, ret)
72
81
  %w(attachment sectionsplit index presentation-xml
73
82
  bare-after-first).each do |s|
74
83
  ret[s.gsub("-", "").to_sym] = ref[s] if ref[s]
75
84
  end
76
- ret.compact
77
85
  end
78
86
 
79
87
  def add_suffix_to_attributes(doc, suffix, tag_name, attribute_name)
@@ -4,7 +4,7 @@ module Metanorma
4
4
  def add_section_split
5
5
  ret = @files.keys.each_with_object({}) do |k, m|
6
6
  if @files[k][:sectionsplit] == "true" && !@files[k]["attachment"]
7
- s, manifest = sectionsplit(@files[k][:ref], k)
7
+ s, manifest = sectionsplit(@files[k][:ref], @files[k][:out_path], k)
8
8
  s.each_with_index { |f1, i| add_section_split_instance(f1, m, k, i) }
9
9
  m["#{k}:index.html"] = add_section_split_cover(manifest, k)
10
10
  @files_to_delete << m["#{k}:index.html"][:ref]
@@ -54,10 +54,10 @@ module Metanorma
54
54
  [presfile, newkey, xml]
55
55
  end
56
56
 
57
- def sectionsplit(file, ident)
57
+ def sectionsplit(file, outfile, ident)
58
58
  @sectionsplit = Sectionsplit
59
- .new(input: file, base: File.basename(file), dir: File.dirname(file),
60
- output: file, compile_options: @parent.compile_options,
59
+ .new(input: file, base: outfile, dir: File.dirname(file),
60
+ output: outfile, compile_options: @parent.compile_options,
61
61
  fileslookup: self, ident: ident, isodoc: @isodoc)
62
62
  coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
63
63
  xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
@@ -18,7 +18,8 @@ module Metanorma
18
18
  end
19
19
 
20
20
  def input_to_isodoc(file, filename, options = {})
21
- Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend, options)
21
+ Metanorma::Input::Asciidoc.new.process(file, filename,
22
+ @asciidoctor_backend, options)
22
23
  end
23
24
 
24
25
  # def input_to_isodoc(file, filename)
@@ -33,12 +34,17 @@ module Metanorma
33
34
  end
34
35
  end
35
36
 
37
+ def options_preprocess(options)
38
+ options[:output_formats] = output_formats
39
+ end
40
+
36
41
  def output(isodoc_node, _inname, outname, _format, _options = {})
37
42
  File.open(outname, "w:UTF-8") { |f| f.write(isodoc_node) }
38
43
  end
39
44
 
40
45
  def extract_options(file)
41
46
  Metanorma::Input::Asciidoc.new.extract_options(file)
47
+ .merge(output_formats: output_formats)
42
48
  end
43
49
 
44
50
  def extract_metanorma_options(file)
@@ -65,8 +65,12 @@ module Metanorma
65
65
  @seen_filenames = []
66
66
  end
67
67
 
68
+ def strip_root(name)
69
+ name.sub(%r{^(\./)?(\.\./)+}, "")
70
+ end
71
+
68
72
  def source2dest_filename(name, disambig = true)
69
- n = name.sub(%r{^(\./)?(\.\./)+}, "")
73
+ n = strip_root(name)
70
74
  dir = File.dirname(n)
71
75
  base = File.basename(n)
72
76
  if disambig && @seen_filenames.include?(base)
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "1.6.4".freeze
2
+ VERSION = "1.6.5".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.6.4
4
+ version: 1.6.5
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-10-09 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor