metanorma 2.5.16 → 2.5.17

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: 9677e770c8876f2e5a74e3f8acdc53d4882ec3e51cb3b997c5946a927adf994f
4
- data.tar.gz: 1553466c032a992f29cf62f4893aa9e4897a0221180e29e5cb3604a77f9bd74b
3
+ metadata.gz: e74645aab84c8445fdcbdab1190af0c3e885aa315b987d9f608c6633d2453fd0
4
+ data.tar.gz: e71224bccf1879c5356ad8420b638d31de3bfa4f602fbed210328990965c1e2b
5
5
  SHA512:
6
- metadata.gz: 6c9aa9f655bc1229da61f2ce82894a17fbca9d1be9d2f643a4c8c19a669d4bc93389ca7671d14c2df813590391ce763f840ab6bbb8166349a3051790e4b70188
7
- data.tar.gz: 7fa9f94228a0ccfa02bc9ba65d11e7a543581e0ae889449375ff99d82cb5d9543e419f02cd780f2e9b4553040cc6eb3df91abb2e621876ecc0247eb52956b4e1
6
+ metadata.gz: e499614dc2d81c316a92908f5bd22e1fff19b92095ccbabff70a1411bd011e4e7fbef871a490c9ed3d17d76d3ed20ceebcf6c967b7503a6ca4a2756dfe974eeb
7
+ data.tar.gz: 56c95bb8a97425b3b6f3106f91fd5c92fba09383d135251fc2c4998c35f4ba88244b849b9f11a23eb08d8280699cdcb58a12cc448db91d6658b95305c3408104
@@ -4,6 +4,24 @@ module Metanorma
4
4
  SVG_NS = "http://www.w3.org/2000/svg".freeze
5
5
  XLINK_NS = "http://www.w3.org/1999/xlink".freeze
6
6
 
7
+ class << self
8
+ # Reference-type svgmap targets (eref[@bibitemid]) resolve to the
9
+ # reference list. Where a flavor's references are ALSO declared as
10
+ # page anchors, the flavor registers a resolver mapping its
11
+ # reference identity to an anchor record; the registry is empty in
12
+ # core, which carries no domain knowledge. A resolver receives
13
+ # (reference_name, lookup) and returns an anchor record
14
+ # ({ key:, id:, url: }) or nil; lookup maps a plain anchor base to
15
+ # a record, edition-suffix chains included.
16
+ def reference_anchor_resolvers
17
+ @reference_anchor_resolvers ||= []
18
+ end
19
+
20
+ def register_reference_anchor_resolver(&resolver)
21
+ reference_anchor_resolvers << resolver
22
+ end
23
+ end
24
+
7
25
  # Converts SVG images to data URIs for inline embedding
8
26
  def svg_datauri(docxml, docid)
9
27
  rel = @files.get(docid, :rel_path)
@@ -170,6 +188,22 @@ module Metanorma
170
188
  x.name = "link"
171
189
  x["target"] = href
172
190
  end
191
+ # Reference-type targets (eref[@bibitemid]) resolve to the reference
192
+ # list. Where a domain's references are ALSO declared as page
193
+ # anchors, that domain registers a resolver mapping the reference
194
+ # identity to an anchor record; core registers none and carries no
195
+ # domain knowledge. Resolvers receive (reference_name, lookup),
196
+ # where lookup maps a plain anchor base to a record.
197
+ lookup = ->(base) { hotspot_prefix_lookup(idx, base) }
198
+ docxml.xpath(ns("//svgmap/target/eref[@bibitemid]")).each do |e|
199
+ rec = self.class.reference_anchor_resolvers.lazy.map do |resolver|
200
+ resolver.call(e["bibitemid"], lookup)
201
+ end.find(&:itself) or next
202
+ href = hotspot_target_href(rec, docid) or next
203
+ e.name = "link"
204
+ e["target"] = href
205
+ e.attribute_nodes.each { |at| at.remove unless at.name == "target" }
206
+ end
173
207
  end
174
208
 
175
209
  # Rewrites the fragment hrefs of SVG hotspot anchors that do not
@@ -190,11 +224,31 @@ module Metanorma
190
224
  split = hotspot_split_href(a[attr])
191
225
  next unless split
192
226
  page, frag = split
193
- next if page.nil? && page_ids.key?(frag)
227
+ if page.nil? && page_ids.key?(frag)
228
+ # The id exists on this page, but Vectory left the href as a
229
+ # bare relative name (no #): re-point it as the in-page anchor.
230
+ a[attr] = "##{frag}" unless a[attr].start_with?("#")
231
+ next
232
+ end
194
233
  base = hotspot_anchor_base(frag, docid)
195
- next if svg_ids.key?(base) ||
196
- svg_ids.any? { |i, _| i.start_with?("#{base}_") }
197
- rec = idx[frag] || idx[base] or next
234
+ # An SVG element id in this document: anchor the hotspot in-page.
235
+ in_page = if svg_ids.key?(frag)
236
+ frag
237
+ else
238
+ svg_ids.keys.find { |i| i.start_with?("#{base}_") }
239
+ end
240
+ if in_page
241
+ a[attr] = "##{in_page}"
242
+ next
243
+ end
244
+ rec = idx[frag] || idx[base] ||
245
+ hotspot_prefix_lookup(idx, base)
246
+ unless rec
247
+ # Unresolvable bare name: a dead link (relative file or
248
+ # dangling fragment) is worse than no link; drop the href.
249
+ a.remove_attribute(attr)
250
+ next
251
+ end
198
252
  href = hotspot_target_href(rec, docid) or next
199
253
  href = "#{page}#{href}" if page && rec[:key] == docid
200
254
  a[attr] = href unless href == a[attr]
@@ -309,6 +363,22 @@ module Metanorma
309
363
  rec[:url] or return nil
310
364
  "#{hotspot_relative_url(rec[:url], docid)}##{rec[:id]}"
311
365
  end
366
+
367
+ # Exact base first, then a unique prefix match: a declaration id
368
+ # carries the owning member's edition suffix chain behind the plain
369
+ # name (geometry_schema.cartesian_point_ISO_10303-42_2025_...), so
370
+ # the plain name resolves by prefix. Multiple equal-length matches
371
+ # are ambiguous and refuse, as do differing ids at the same key.
372
+ def hotspot_prefix_lookup(idx, prefix)
373
+ return idx[prefix] if idx[prefix]
374
+
375
+ candidates = idx.select { |k, r| r && k.start_with?("#{prefix}_") }
376
+ return nil if candidates.empty?
377
+
378
+ shortest = candidates.min_by { |k, _| k.length }
379
+ ties = candidates.count { |k, _| k.length == shortest[0].length }
380
+ ties == 1 ? shortest[1] : nil
381
+ end
312
382
  end
313
383
  end
314
384
  end
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.5.16".freeze
2
+ VERSION = "2.5.17".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.5.16
4
+ version: 2.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-06 00:00:00.000000000 Z
11
+ date: 2026-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor