metanorma 2.1.8 → 2.1.9

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: b2491a406715a008c828e167a72d00c415af554237517bcbfdeb76818545d548
4
- data.tar.gz: 5e7a842f9fa86b6cbd8ec4ff5730489ba3ff89330d4d74aa6a7de1f4ece68f0d
3
+ metadata.gz: b6f662b6213511d30fb8f16f0bc51bb4209959a4f17ac385d81bdd02f1135088
4
+ data.tar.gz: 4021db66267ad5cbc213058d7b2252d6a2f9572e6efd686df2f84ba1f1965cbb
5
5
  SHA512:
6
- metadata.gz: 42c9068a65961a2c785b0ee3d5cfcdc9710bcfffeb8309b4bb91b7b213cd9fa97ffff220586f1d9b52d2b230c9cb4743180d3e25209a9e4dfb22cb14d6f89468
7
- data.tar.gz: de9167c3dddad4904aba5101a9cea1864654eea8549a6d45eff4fe6bc8d266ea927356b769ef6090126f0177d4c725d0f9059be2c9de0ec7816f3e68c5976081
6
+ metadata.gz: 6ba138f8fd28e6e4ee1d0fcc786f49b17b816483c39a6d2dda89643b9611bed93068ac8f3e700ba199a01f0f0446ce2c46be97d4a7e705a67df04e6b1d898432
7
+ data.tar.gz: 45a50ed06452ff4e598bc95ce07412eeca39b33afe7158a48f17080381417cda79ba4ed4286901652a6e4f6311d0ad70e083388aba4e3150c22f543f56825dde
@@ -68,6 +68,8 @@ module Metanorma
68
68
  def from_xml(xml)
69
69
  b = xml.at("//xmlns:bibitem|//xmlns:bibdata")
70
70
  r = mn2relaton_parser(xml.root.name)
71
+ # Relaton doesn't understand Pres XML tags
72
+ b.xpath("//xmlns:fmt-identifier").each(&:remove)
71
73
  r.from_xml(b.to_xml)
72
74
  end
73
75
 
@@ -18,6 +18,7 @@ module Metanorma
18
18
  @parent = parent
19
19
  @xml = parent.xml
20
20
  @isodoc = parent.isodoc
21
+ @isodoc_presxml = parent.isodoc_presxml
21
22
  @path = path
22
23
  @compile = parent.compile
23
24
  @documents = parent.documents
@@ -131,7 +132,7 @@ module Metanorma
131
132
 
132
133
  def add_document_suffix(identifier, doc)
133
134
  document_suffix = Metanorma::Utils::to_ncname(identifier)
134
- Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
135
+ Util::anchor_id_attributes.each do |(tag_name, attr_name)|
135
136
  Util::add_suffix_to_attrs(doc, document_suffix, tag_name, attr_name,
136
137
  @isodoc)
137
138
  end
@@ -230,7 +231,6 @@ module Metanorma
230
231
  ret = {}
231
232
  xml.traverse do |x|
232
233
  x.text? and next
233
- /^semantic__/.match?(x.name) and next
234
234
  x["id"] and ret[x["id"]] = true
235
235
  end
236
236
  ret
@@ -110,8 +110,9 @@ module Metanorma
110
110
  @sectionsplit = ::Metanorma::Collection::Sectionsplit
111
111
  .new(input: file, base: @files[ident][:out_path],
112
112
  dir: File.dirname(file), output: @files[ident][:out_path],
113
- compile_opts: @parent.compile_options,
114
- fileslookup: self, ident: ident, isodoc: @isodoc,
113
+ compile_opts: @parent.compile_options, ident: ident,
114
+ fileslookup: self, isodoc: @isodoc,
115
+ isodoc_presxml: @isodoc_presxml,
115
116
  document_suffix: @files[ident][:document_suffix])
116
117
  coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
117
118
  xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
@@ -16,8 +16,6 @@ module Metanorma
16
16
  # @return [String] XML content
17
17
  def update_xrefs(file, docid, internal_refs)
18
18
  xml, sso = update_xrefs_prep(file, docid)
19
- #require "debug"; binding.b if /This document is also unrelated/.match?(xml.to_xml)
20
- #warn (/fmt-title/.match?(xml.to_xml) ? "*** PRESENTATION" : "*** SEMANTIC")
21
19
  @nested || sso or
22
20
  Metanorma::Collection::XrefProcess::xref_process(xml, xml, nil, docid,
23
21
  @isodoc, sso)
@@ -26,7 +24,7 @@ module Metanorma
26
24
  @files.add_document_suffix(docid, xml)
27
25
  @nested or update_sectionsplit_refs_to_docs(xml, internal_refs, sso)
28
26
  update_direct_refs_to_docs(xml, docid, sso)
29
- hide_refs(xml)
27
+ ::Metanorma::Collection::Util::hide_refs(xml)
30
28
  sso and eref2link(xml, sso)
31
29
  @nested or svgmap_resolve(xml, docid, sso)
32
30
  xml.to_xml
@@ -109,7 +107,6 @@ module Metanorma
109
107
  else no_anchor[k] << e end
110
108
  end
111
109
  end
112
- #require "debug"; binding.b
113
110
  [erefs, no_anchor, anchors, Util::gather_bibitemids(docxml, presxml)]
114
111
  end
115
112
 
@@ -128,8 +125,9 @@ module Metanorma
128
125
 
129
126
  # Resolve erefs to a container of ids in another doc,
130
127
  # to an anchor eref (direct link)
131
- def update_indirect_refs_to_docs(docxml, _docidentifier, internal_refs, presxml)
132
- bib, erefs, doc_suffix, doc_type, f = update_indirect_refs_prep(docxml, presxml)
128
+ def update_indirect_refs_to_docs(docxml, _docid, internal_refs, presxml)
129
+ bib, erefs, doc_suffix, doc_type, f = update_indirect_refs_prep(docxml,
130
+ presxml)
133
131
  internal_refs.each do |schema, ids|
134
132
  add_suffix = doc_suffix && doc_type && doc_type != schema
135
133
  ids.each do |id, file|
@@ -149,37 +147,15 @@ module Metanorma
149
147
  docxml.root["document_suffix"], docxml.root["type"], {}]
150
148
  end
151
149
 
152
- # KILL
153
- def indirect_ref_key(schema, id, doc_suffix, doc_type)
154
- /^#{schema}_/.match?(id) and return id
155
- key = [schema, id, doc_suffix, doc_type].join("::")
156
- x = @indirect_keys[key] and return x
157
- ret = "#{schema}_#{id}"
158
- doc_suffix && doc_type && doc_type != schema and
159
- ret = "#{ret}_#{doc_suffix}"
160
- @indirect_keys[key] = ret
161
- ret
162
- end
163
-
164
150
  def indirect_ref_key(schema, id, doc_suffix, add_suffix)
165
151
  /^#{schema}_/.match?(id) and return id
166
- #key = "#{schema}_#{id}"
167
152
  x = @indirect_keys.dig(schema, id) and return x
168
153
  @indirect_keys[schema] ||= {}
169
154
  @indirect_keys[schema][id] = if add_suffix
170
- "#{schema}_#{id}_#{doc_suffix}"
171
- else
172
- "#{schema}_#{id}"
173
- end
174
- end
175
-
176
- # KILL
177
- def indirect_ref_keyx(schema, id, doc_suffix, doc_type)
178
- /^#{schema}_/.match?(id) and return id
179
- ret = "#{schema}_#{id}"
180
- doc_suffix && doc_type && doc_type != schema and
181
- ret = "#{ret}_#{doc_suffix}"
182
- ret
155
+ "#{schema}_#{id}_#{doc_suffix}"
156
+ else
157
+ "#{schema}_#{id}"
158
+ end
183
159
  end
184
160
 
185
161
  def update_indirect_refs_to_docs1(filec, key, file, bibitems, erefs)
@@ -196,13 +172,10 @@ module Metanorma
196
172
  parentid and file = "#{parentid}_#{file}"
197
173
  existing = a.text
198
174
  anchor = if url then existing
199
- else
200
- #suffix_anchor_indirect(existing, suffix)
201
- #k = "#{existing}_#{file}"
202
- #@ncnames[k] ||= Metanorma::Utils::to_ncname(k)
203
- @indirect_keys[existing] ||= {}
204
- @indirect_keys[existing][file] ||= Metanorma::Utils::to_ncname("#{existing}_#{file}")
205
- end
175
+ else
176
+ @indirect_keys[existing] ||= {}
177
+ @indirect_keys[existing][file] ||= Metanorma::Utils::to_ncname("#{existing}_#{file}")
178
+ end
206
179
  @updated_anchors[existing] or a.children = anchor
207
180
  @updated_anchors[anchor] = true
208
181
  end
@@ -15,7 +15,7 @@ module Metanorma
15
15
  class Renderer
16
16
  FORMATS = %i[html xml doc pdf].freeze
17
17
 
18
- attr_accessor :isodoc, :nested
18
+ attr_accessor :isodoc, :isodoc_presxml, :nested
19
19
  attr_reader :xml, :compile, :compile_options, :documents, :outdir,
20
20
  :manifest
21
21
 
@@ -45,6 +45,8 @@ module Metanorma
45
45
 
46
46
  # output processor for flavour
47
47
  @isodoc = Util::isodoc_create(@flavor, @lang, @script, @xml)
48
+ @isodoc_presxml = Util::isodoc_create(@flavor, @lang, @script, @xml,
49
+ presxml: true)
48
50
  @outdir = dir_name_cleanse(options[:output_folder])
49
51
  @coverpage = options[:coverpage] || collection.coverpage
50
52
  @format = ::Metanorma::Util.sort_extensions_execution(options[:format])
@@ -17,6 +17,7 @@ module Metanorma
17
17
  newbib["hidden"] = "true"
18
18
  newbib&.at("./*[local-name() = 'ext']")&.remove
19
19
  newbib["id"] = bib["id"]
20
+ bib["anchor"] and newbib["anchor"] = bib["anchor"]
20
21
  newbib
21
22
  end
22
23
 
@@ -37,17 +38,10 @@ module Metanorma
37
38
  end
38
39
  end
39
40
 
40
- def hide_refs(docxml)
41
- docxml.xpath(ns("//references[bibitem][not(./bibitem[not(@hidden) or " \
42
- "@hidden = 'false'])]")).each do |f|
43
- f["hidden"] = "true"
44
- end
45
- end
46
-
47
41
  def new_hidden_ref(xmldoc)
48
42
  ins = xmldoc.at(ns("bibliography")) or
49
43
  xmldoc.root << "<bibliography/>" and ins = xmldoc.at(ns("bibliography"))
50
- ins.at(ns("./referenced[@hidden = 'true']")) or
44
+ ins.at(ns("./references[@hidden = 'true']")) or
51
45
  ins.add_child("<references hidden='true' normative='false'/>").first
52
46
  end
53
47
 
@@ -81,7 +75,7 @@ module Metanorma
81
75
  refs.each do |k, v|
82
76
  url = @files.url(v, {})
83
77
  ins << <<~XML
84
- <bibitem id="#{k}">#{docid_xml(v)}<uri type='citation'>#{url}</uri></bibitem>
78
+ <bibitem id="#{k}" anchor="#{k}">#{docid_xml(v)}<uri type='citation'>#{url}</uri></bibitem>
85
79
  XML
86
80
  end
87
81
  end
@@ -39,6 +39,7 @@ module Metanorma
39
39
  end
40
40
 
41
41
  def collectionyaml(files, xml)
42
+ #warn xml.to_xml
42
43
  ret = {
43
44
  directives: ["presentation-xml", "bare-after-first"],
44
45
  bibdata: {
@@ -19,6 +19,7 @@ module Metanorma
19
19
  @fileslookup = opts[:fileslookup]
20
20
  @ident = opts[:ident]
21
21
  @isodoc = opts[:isodoc]
22
+ @isodoc_presxml = opts[:isodoc_presxml]
22
23
  @document_suffix = opts[:document_suffix]
23
24
  end
24
25
 
@@ -32,18 +33,19 @@ module Metanorma
32
33
  ["//bibliography/*[not(@hidden = 'true')]", "bibliography"],
33
34
  ["//indexsect", nil], ["//colophon", nil]].freeze
34
35
 
35
- # Input XML is Semantic
36
+ # Input XML is Semantic XML
36
37
  def sectionsplit
37
38
  xml = sectionsplit_prep(File.read(@input_filename), @base, @dir)
38
39
  @key = Metanorma::Collection::XrefProcess::xref_preprocess(xml, @isodoc)
39
40
  empty = empty_doc(xml)
40
41
  empty1 = empty_attachments(empty)
41
42
  @mutex = Mutex.new
42
- #@pool = Concurrent::FixedThreadPool.new(4)
43
+ # @pool = Concurrent::FixedThreadPool.new(4)
43
44
  @pool = Concurrent::FixedThreadPool.new(1)
44
45
  sectionsplit1(xml, empty, empty1, 0)
45
46
  end
46
47
 
48
+ # xml is Presentation XML
47
49
  def sectionsplit1(xml, empty, empty1, idx)
48
50
  ret = SPLITSECTIONS.each_with_object([]) do |n, m|
49
51
  conflate_floatingtitles(xml.xpath(ns(n[0]))).each do |s|
@@ -59,12 +61,14 @@ module Metanorma
59
61
 
60
62
  def sectionsplit2(xml, empty, chunks, parentnode, opt)
61
63
  @pool.post do
64
+ warn "#{@base}.#{opt[:idx]}"
62
65
  a = sectionfile(xml, empty, "#{@base}.#{opt[:idx]}", chunks,
63
66
  parentnode)
64
67
  @mutex.synchronize { opt[:acc] << a }
65
68
  end
66
69
  end
67
70
 
71
+ # TODO move to metanorma-utils
68
72
  def block?(node)
69
73
  %w(p table formula admonition ol ul dl figure quote sourcecode example
70
74
  pre note pagebreak hr bookmark requirement recommendation permission
@@ -86,7 +90,6 @@ module Metanorma
86
90
  xml, type = sectionsplit_preprocess_semxml(file, filename)
87
91
  flags = { format: :asciidoc, extension_keys: [:presentation],
88
92
  type: type }.merge(@compile_opts)
89
- #require "debug"; binding.b
90
93
  Compile.new.compile(xml, flags)
91
94
  f = File.open(xml.sub(/\.xml$/, ".presentation.xml"), encoding: "utf-8")
92
95
  r = Nokogiri::XML(f, &:huge)
@@ -109,7 +112,6 @@ module Metanorma
109
112
  if c = @fileslookup&.parent
110
113
  n = c.nested
111
114
  c.nested = true # so unresolved erefs are not deleted
112
- #require "debug"; binding.b
113
115
  c.update_xrefs(xml, @ident, {})
114
116
  c.nested = n
115
117
  xml.xpath("//xmlns:svgmap").each { |x| x.name = "svgmap1" }
@@ -125,35 +127,19 @@ module Metanorma
125
127
  outname
126
128
  end
127
129
 
128
- def emptydoc(xml, ordinal)
129
- out = xml.dup
130
- out.xpath(
131
- ns("//preface | //sections | //annex | //bibliography/clause | " \
132
- "//bibliography/references[not(@hidden = 'true')] | " \
133
- "//indexsect | //colophon"),
134
- ).each(&:remove)
135
- ordinal.zero? or out.xpath(ns("//metanorma-ext//attachment | " \
136
- "//semantic__metanorma-ext//semantic__attachment"))
137
- .each(&:remove) # keep only one copy of attachments
138
- out
139
- end
140
-
141
130
  def empty_doc(xml)
142
131
  out = xml.dup
143
132
  out.xpath(
144
- ns("//preface | //sections | //annex | //bibliography/clause | " \
145
- "//bibliography/references[not(@hidden = 'true')] | " \
146
- "//indexsect | //colophon"),
133
+ ns("//preface | //sections | //annex | " \
134
+ "//references/bibitem[not(@hidden = 'true')] | " \
135
+ "//indexsect | //colophon"),
147
136
  ).each(&:remove)
137
+ ::Metanorma::Collection::Util::hide_refs(out)
148
138
  out
149
139
  end
150
140
 
151
141
  def empty_attachments(xml)
152
- out = xml.dup
153
- out.xpath(ns("//metanorma-ext//attachment | " \
154
- "//semantic__metanorma-ext//semantic__attachment"))
155
- .each(&:remove) # keep only one copy of attachments
156
- out
142
+ xml.dup
157
143
  end
158
144
 
159
145
  def sectionfile(fulldoc, xml, file, chunks, parentnode)
@@ -164,11 +150,10 @@ module Metanorma
164
150
 
165
151
  def create_sectionfile(xml, out, file, chunks, parentnode)
166
152
  ins = out.at(ns("//metanorma-extension")) || out.at(ns("//bibdata"))
167
- #require "debug"; binding.b
168
153
  sectionfile_insert(ins, chunks, parentnode)
154
+ sectionfile_fn_filter(sectionfile_review_filter(out))
169
155
  Metanorma::Collection::XrefProcess::xref_process(out, xml, @key,
170
156
  @ident, @isodoc, true)
171
- #truncate_semxml(out, chunks)
172
157
  outname = "#{file}.xml"
173
158
  File.open(File.join(@splitdir, outname), "w:UTF-8") do |f|
174
159
  f.write(out)
@@ -176,36 +161,86 @@ module Metanorma
176
161
  outname
177
162
  end
178
163
 
179
- # KILL
180
- def semantic_xml_ids_gather(out)
181
- out.at(ns("//semantic__bibdata")) or return
182
- SPLITSECTIONS.each_with_object({}) do |s, m|
183
- out.xpath(ns(s[0].sub("//", "//semantic__"))).each do |x|
184
- x["id"] or next
185
- m[x["id"].sub(/^semantic__/, "")] = x
164
+ def sectionfile_insert(ins, chunks, parentnode)
165
+ if parentnode
166
+ ins.next = "<#{parentnode}/>"
167
+ chunks.each { |c| ins.next.add_child(c.dup) }
168
+ else chunks.each { |c| ins.next = c.dup }
169
+ end
170
+ end
171
+
172
+ def sectionfile_fn_filter(xml)
173
+ ids = sectionfile_fn_filter_prep(xml)
174
+ xml.root.xpath(ns("./fmt-footnote-container/fmt-fn-body")).each do |f|
175
+ ids.has_key?(f["id"]) or f.remove
176
+ end
177
+ seen = {}
178
+ xml.root.xpath(ns("/fmt-footnote-container/fmt-fn-body"))
179
+ .each_with_index do |fnbody, i|
180
+ sectionfile_fn_filter_renumber(fnbody, i, ids, seen)
186
181
  end
182
+ xml
183
+ end
184
+
185
+ # map fmt-fn-body/@id = fn/@target to fn
186
+ def sectionfile_fn_filter_prep(xml)
187
+ xml.xpath(ns("//fn")).each_with_object({}) do |f, m|
188
+ m[f["target"]] ||= []
189
+ m[f["target"]] << f
187
190
  end
188
191
  end
189
192
 
190
- # KILL
191
- def semxml_presxml_nodes_match(nodes, chunks)
192
- chunks.each do |x|
193
- nodes[x["id"]] and nodes.delete(x["id"])
193
+ FN_CAPTIONS = ".//fmt-fn-label/span[@class = 'fmt-caption-label']".freeze
194
+
195
+ def sectionfile_fn_filter_renumber(fnbody, idx, ids, seen)
196
+ sectionfile_fn_filter_fn_renumber(fnbody, idx, ids, seen)
197
+ sectionfile_fn_filter_fnbody_renumber(fnbody, idx, ids)
198
+ end
199
+
200
+ def sectionfile_fn_filter_fn_renumber(fnbody, idx, ids, seen)
201
+ ids[fnbody["id"]].each do |f|
202
+ @isodoc_presxml.renumber_document_footnote(f, idx, seen)
203
+ fnlabel = f.at(ns(FN_CAPTIONS)) and
204
+ fnlabel.children = @isodoc_presxml.fn_ref_label(f)
194
205
  end
195
206
  end
196
207
 
197
- # KILL
198
- def truncate_semxml(out, chunks)
199
- nodes = semantic_xml_ids_gather(out) or return
200
- semxml_presxml_nodes_match(nodes, chunks)
201
- nodes.each_value(&:remove)
208
+ def sectionfile_fn_filter_fnbody_renumber(fnbody, _idx, ids)
209
+ fnlabel = fnbody.at(ns(FN_CAPTIONS)) or return
210
+ fnbody["reference"] = ids[fnbody["id"]].first["reference"]
211
+ fnlabel.children = @isodoc_presxml.fn_body_label(fnbody)
202
212
  end
203
213
 
204
- def sectionfile_insert(ins, chunks, parentnode)
205
- if parentnode
206
- ins.next = "<#{parentnode}/>"
207
- chunks.each { |c| ins.next.add_child(c.dup) }
208
- else chunks.each { |c| ins.next = c.dup }
214
+ # map fmt-review-body/@id = fmt-review-{start/end}/@target
215
+ # to fmt-review-{stary/end}
216
+ def sectionfile_review_filter_prep(xml)
217
+ xml.xpath(ns("//fmt-review-start | //fmt-review-end"))
218
+ .each_with_object({}) do |f, m|
219
+ m[f["target"]] ||= []
220
+ m[f["target"]] << f
221
+ end
222
+ end
223
+
224
+ def sectionfile_review_filter(xml)
225
+ ids = sectionfile_review_filter_prep(xml)
226
+ xml.root.xpath(ns("./review-container/fmt-review-body")).each do |f|
227
+ ids.has_key?(f["id"]) or f.remove
228
+ end
229
+ xml.root.xpath(ns("./review-container/fmt-review-body"))
230
+ .each_with_index do |fnbody, i|
231
+ sectionfile_review_filter_renumber(fnbody, i, ids)
232
+ end
233
+ xml
234
+ end
235
+
236
+ def sectionfile_review_filter_renumber(fnbody, _idx, ids)
237
+ ids[fnbody["id"]].each do |f|
238
+ case f.name
239
+ when "fmt-review-start"
240
+ f.children = @isodoc_presxml.comment_bookmark_start_label(f)
241
+ when "fmt-review-end"
242
+ f.children = @isodoc_presxml.comment_bookmark_end_label(f)
243
+ end
209
244
  end
210
245
  end
211
246
 
@@ -214,7 +249,7 @@ module Metanorma
214
249
  t = title.dup
215
250
  t.xpath(ns(".//tab | .//br")).each { |x| x.replace(" ") }
216
251
  t.xpath(ns(".//bookmark")).each(&:remove)
217
- t.xpath('.//text()').map(&:text).join
252
+ t.xpath(".//text()").map(&:text).join
218
253
  end
219
254
  end
220
255
  end
@@ -2,6 +2,11 @@ module Metanorma
2
2
  class Collection
3
3
  module Util
4
4
  class << self
5
+ def anchor_id_attributes
6
+ Metanorma::Utils::anchor_attributes(presxml: true) +
7
+ [%w(* id), %w(* anchor), %w(link bibitemid), %w(fmt-link bibitemid)]
8
+ end
9
+
5
10
  def gather_bibitems(xml)
6
11
  xml.xpath("//xmlns:bibitem[@id]").each_with_object({}) do |b, m|
7
12
  if m[b["id"]]
@@ -16,7 +21,6 @@ module Metanorma
16
21
 
17
22
  def gather_bibitemids(xml, presxml)
18
23
  xml.xpath("//*[@bibitemid]").each_with_object({}) do |e, m|
19
- #/^semantic__/.match?(e.name) and next
20
24
  presxml && %w(xref eref link).include?(e.name) and next
21
25
  m[e["bibitemid"]] ||= []
22
26
  m[e["bibitemid"]] << e
@@ -25,7 +29,6 @@ module Metanorma
25
29
 
26
30
  def gather_citeases(xml, presxml)
27
31
  xml.xpath("//*[@citeas]").each_with_object({}) do |e, m|
28
- #/^semantic__/.match?(e.name) and next
29
32
  presxml && %w(xref eref link).include?(e.name) and next
30
33
  k = key(e["citeas"])
31
34
  m[k] ||= []
@@ -36,6 +39,8 @@ module Metanorma
36
39
  def add_suffix_to_attrs(doc, suffix, tag_name, attr_name, isodoc)
37
40
  (suffix.nil? || suffix.empty?) and return
38
41
  doc.xpath(isodoc.ns("//#{tag_name}[@#{attr_name}]")).each do |elem|
42
+ #warn "#{tag_name} : #{elem.name}" if attr_name == "bibitemid"
43
+ #require 'debug'; binding.b if attr_name == "bibitemid" && #!%w(eref fmt-eref link fmt-link).include?(elem.name)
39
44
  a = elem.attributes[attr_name].value
40
45
  /_#{suffix}$/.match?(a) or
41
46
  elem.attributes[attr_name].value = "#{a}_#{suffix}"
@@ -55,6 +60,14 @@ module Metanorma
55
60
  p.absolute? ? path : File.join(dir, path)
56
61
  end
57
62
 
63
+ def hide_refs(docxml)
64
+ p = "//xmlns:references[xmlns:bibitem]"\
65
+ "[not(./xmlns:bibitem[not(@hidden) or @hidden = 'false'])]"
66
+ docxml.xpath(p).each do |f|
67
+ f["hidden"] = "true"
68
+ end
69
+ end
70
+
58
71
  def key(ident)
59
72
  @c ||= HTMLEntities.new
60
73
  @c.decode(ident).gsub(/(\p{Zs})+/, " ")
@@ -67,20 +80,20 @@ module Metanorma
67
80
  def load_isodoc(flavor, presxml: false)
68
81
  x = Asciidoctor.load nil, backend: flavor.to_sym
69
82
  if presxml
70
- x.converter.presentation_xml_converter(Dummy.new)
83
+ x.converter.presentation_xml_converter(Dummy.new)
71
84
  else
72
- x.converter.html_converter(Dummy.new) # to obtain Isodoc class
85
+ x.converter.html_converter(Dummy.new) # to obtain Isodoc class
73
86
  end
74
87
  end
75
88
 
76
89
  def isodoc_create(flavor, lang, script, xml, presxml: false)
77
- isodoc = Util::load_isodoc(flavor, presxml: presxml)
78
- isodoc.i18n_init(lang, script, nil) # read in internationalisation
79
- # TODO locale?
80
- isodoc.metadata_init(lang, script, nil, isodoc.i18n)
81
- isodoc.info(xml, nil)
82
- isodoc
83
- end
90
+ isodoc = Util::load_isodoc(flavor, presxml: presxml)
91
+ isodoc.i18n_init(lang, script, nil) # read in internationalisation
92
+ # TODO locale?
93
+ isodoc.metadata_init(lang, script, nil, isodoc.i18n)
94
+ isodoc.info(xml, nil)
95
+ isodoc
96
+ end
84
97
  end
85
98
  end
86
99
  end
@@ -10,8 +10,7 @@ module Metanorma
10
10
  @isodoc = isodoc
11
11
  key = (0...8).map { rand(65..90).chr }.join # random string
12
12
  xml.root["type"] = key
13
- Metanorma::Utils::anchor_attributes
14
- .each do |(tag_name, attr_name)|
13
+ Util::anchor_id_attributes.each do |(tag_name, attr_name)|
15
14
  #tag_name == "xref" and tag_name = "fmt-xref"
16
15
  ::Metanorma::Collection::Util::add_suffix_to_attrs(
17
16
  xml, xml.root["document_suffix"], tag_name, attr_name, isodoc
@@ -225,7 +224,7 @@ module Metanorma
225
224
 
226
225
  def new_indirect_bibitem(ident, prefix)
227
226
  <<~BIBENTRY
228
- <bibitem id="#{ident}" type="internal">
227
+ <bibitem id="#{ident}" anchor="#{ident}" type="internal">
229
228
  <docidentifier type="repository">#{ident.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
230
229
  </bibitem>
231
230
  BIBENTRY
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.1.8".freeze
2
+ VERSION = "2.1.9".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: 2.1.8
4
+ version: 2.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-29 00:00:00.000000000 Z
11
+ date: 2025-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor