metanorma-standoc 3.5.1.pre.alpha.3 → 3.5.1.pre.alpha.4

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: 79b37a413932b28bdbdaa5564347f846c2a1fdb3722c6201d5f688e80af65d03
4
- data.tar.gz: 94adfc8f36c38c305be115769c7e5cfca64a6babda01e83261b6202f07d3cec2
3
+ metadata.gz: e8f41ce37c36a6738ac98eb9e86bb5138321e7589211ad2707d936b43b552014
4
+ data.tar.gz: 7fadb5258380cb3b8eaa287373d74be84eea3d2da1c2bb828009eb2cecf3e615
5
5
  SHA512:
6
- metadata.gz: 1dc0236ec7ce90db11c8b8606299ef21c1c444ea84b9391517bd98f8cb8b5df5482e0b1f35d8ac75623ab2ce44e7ab1b042e1d1f89563a2a4374a31c7b12ce8e
7
- data.tar.gz: 1ab82ac3c1f076d09d2ee443a6b5ac26500cb5eb7be9680f2d6a4e7e3dbf6ea77f11c441d543fb690b6740a9ea167cffec8ed3d1c818553bae941c0e2764ec0f
6
+ metadata.gz: 8df61e622e50667ba826c7a25326f6deb289a70db9c61640ff110fe42746a9fce0e9280845b828d2cf5ffa4e41bbd724d385260695705530d9b4d2e5cbea1673
7
+ data.tar.gz: 113665c40908bd8001d1e98cdd4ce737b27e227170388bbb37508603451585db90a42fec5c7dba989a568eae298754327ff26b46a920d15d0fa0f28a7414f057
@@ -103,9 +103,77 @@ module Metanorma
103
103
  def lookup_refterm(node)
104
104
  target = norm_ref_id1(node)
105
105
  if @lookup[:term][target].nil? && @lookup[:symbol][target].nil?
106
- remove_missing_ref(node, target)
106
+ if (fallback = unique_term_fallback(target, node))
107
+ target = fallback
108
+ else
109
+ remove_missing_ref(node, target)
110
+ return
111
+ end
112
+ end
113
+ if (x = node.at("../xrefrender"))
114
+ modify_ref_node(x, target)
107
115
  else
108
- x = node.at("../xrefrender") and x.name = "xref"
116
+ # bare mention resolved by fallback: the macro left no xrefrender
117
+ ref = Nokogiri::XML::Node.new("xref", @xmldoc)
118
+ ref["target"] = @lookup[:term][target] || target
119
+ node.at("..").add_child(ref)
120
+ end
121
+ end
122
+
123
+ # Mentions are looked up by bare name, but terms in domain-scoped
124
+ # vocabularies are anchored with a domain prefix, so a bare mention
125
+ # misses every key. Resolve a mention whose designation is unique
126
+ # document-wide, or unique within the domain of the term containing
127
+ # the mention.
128
+ # Mentions are looked up by bare name, but terms in domain-scoped
129
+ # vocabularies are anchored with a domain prefix, so a bare mention
130
+ # misses every key. Resolve a mention whose designation is unique
131
+ # document-wide, or unique within the domain of the term containing
132
+ # the mention.
133
+ def unique_term_fallback(target, node)
134
+ cands = @lookup[:term].keys.select do |k|
135
+ k == target || k.end_with?("-#{target}")
136
+ end
137
+ return nil if cands.empty?
138
+ return cands.first if cands.size == 1
139
+
140
+ term = mention_enclosing_term(node) or return nil
141
+ name = first_descendant(term, "name")&.text or return nil
142
+ anchor = term[:anchor] || term["anchor"] or return nil
143
+ name_key = norm_ref_id_text(name)
144
+ prefix_key = anchor.sub(/\Aterm-/, "").sub(/-#{Regexp.escape(name_key)}\z/, "")
145
+ narrowed = cands.select { |k| k.start_with?("#{prefix_key}-") }
146
+ narrowed.size == 1 ? narrowed.first : nil
147
+ end
148
+
149
+ def first_descendant(node, name)
150
+ node.children&.each do |c|
151
+ next unless c.respond_to?(:name)
152
+
153
+ return c if c.name == name
154
+ found = begin
155
+ first_descendant(c, name)
156
+ rescue StandardError
157
+ nil
158
+ end
159
+ return found if found
160
+ end
161
+ nil
162
+ end
163
+
164
+ # The moxml/leptris XML engine's XPath does not support the ancestor
165
+ # axis, and Node#parent is unreliable on XPath-result nodes; hop the
166
+ # parent axis with ".." instead.
167
+ def mention_enclosing_term(node)
168
+ cur = node
169
+ loop do
170
+ cur = begin
171
+ cur&.at("..")
172
+ rescue StandardError
173
+ nil
174
+ end
175
+ return nil if cur.nil?
176
+ return cur if cur.name == "term"
109
177
  end
110
178
  end
111
179
 
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.5.1.pre.alpha.3".freeze
22
+ VERSION = "3.5.1.pre.alpha.4".freeze
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-standoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1.pre.alpha.3
4
+ version: 3.5.1.pre.alpha.4
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-10-27 00:00:00.000000000 Z
11
+ date: 2026-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable