metanorma 2.5.13 → 2.5.15

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: 8e2bbe018164520f24a47304e5a543b33162f139617e751a7bd4a71f5bc4b8c8
4
- data.tar.gz: cd865930cf21c065807ef2d2e357ce3ee41b1c35708ecdb69ea59eb59963f504
3
+ metadata.gz: ab665d7ae21e48a3647a993b72f62bb8f5cbb76338c1e49b651c784e1bc68618
4
+ data.tar.gz: b19a5421c954bdd7954b77acce0e1a7a665779efbfc4987f608e0389c826c6fe
5
5
  SHA512:
6
- metadata.gz: 774a88cefafe5985f8868890f62e1ed552c51a9ffb64cd5b3744394dfe424650a2d32742b48238cb438e03a1ab658ff2681783ad8ed343fcf8d95bc6997ef180
7
- data.tar.gz: fb5f625706d30499551cad94edad5f9aa4f604e3a60c4ab43c0baf3ff83c298d396db5724dc47f58f04545a2d8d0a45afed1fd0d87ad0fa753db09ba9867bc19
6
+ metadata.gz: ea0de64cfac24b46df36301e0f11d6292b180808ab485b7e2b9619c58a7ebcbd20e1fdd6f0cdccef142aec7666a32f16e200f90c400982b2f9a0cfd76dc1ea49
7
+ data.tar.gz: f3eaf23de16cc551adb710c07d4e04f919f1953048695d0ccd7091c1486d79e4fcf9708bcc8354002f2683305b3c2288cb57f9ebc2d57ba2f2ac836cd92a9c0b
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}" }
6
6
 
7
7
  gemspec
8
8
 
9
+ gem "relaton", "~> 3.0"
9
10
  gem "metanorma-core", ">= 0.2.5"
10
11
 
11
12
  # taste stack the compile specs exercise: the oiml taste registers the
@@ -232,6 +232,39 @@ module Metanorma
232
232
  doc.root["document_suffix"] += document_suffix
233
233
  end
234
234
 
235
+ # Re-key a stored document's ids from the suffix it was stored under
236
+ # to this render's own suffix. Reinflation renders stored Semantic
237
+ # XMLs whose ids were keyed by the staging build's identifier; a
238
+ # sectionsplit render splits them into pages whose ids must equal
239
+ # the anchors the cross-reference passes compose from this render's
240
+ # identifiers. Mirror of add_document_suffix with the same
241
+ # attribute, CSS and SVG coverage, replacing the stored suffix
242
+ # instead of appending one. The stored file itself is never written.
243
+ def swap_document_suffix(identifier, doc)
244
+ stored = doc.root["document_suffix"]
245
+ if stored.nil? || stored.empty?
246
+ return add_document_suffix(identifier, doc)
247
+ end
248
+
249
+ suffix = Metanorma::Utils::to_ncname(identifier)
250
+ stored == suffix and return
251
+
252
+ swap_document_suffix_ids(doc, stored, suffix)
253
+ doc.root["document_suffix"] = suffix
254
+ end
255
+
256
+ def swap_document_suffix_ids(doc, stored, suffix)
257
+ base_ids = doc.xpath("./@id | .//@id")
258
+ .map { |a| a.value.sub(/_#{Regexp.escape(stored)}\z/, "") }
259
+ .uniq.to_h { |i| [i, true] }
260
+ Util::anchor_id_attributes.each do |(tag_name, attr_name)|
261
+ Util::swap_suffix_to_attrs(doc, [stored, suffix], tag_name,
262
+ attr_name, @isodoc)
263
+ end
264
+ Util::swap_ids_css(doc, base_ids, stored, suffix)
265
+ Util::swap_svg_ids(doc, base_ids, stored, suffix)
266
+ end
267
+
235
268
  # return citation url for file
236
269
  # @param doc [Boolean] I am a Metanorma document,
237
270
  # so my URL should end with html or pdf or whatever
@@ -34,7 +34,20 @@ module Metanorma
34
34
  @nested or update_indirect_refs_to_docs(xml, docid, internal_refs, sso)
35
35
  # post: bibitem[@type='internal'] anchors resolved to the containing
36
36
  # collection document.
37
- @reinflate or @files.add_document_suffix(docid, xml)
37
+ if sso || !@reinflate
38
+ @files.add_document_suffix(docid, xml)
39
+ elsif @nested
40
+ # Reinflated sectionsplit: the split's Presentation XML was
41
+ # generated from stored XMLs whose ids carry the staging build's
42
+ # suffix, while this render's cross-reference passes compose
43
+ # anchors from this render's identifiers. Re-key the split
44
+ # documents to this render's suffix, so section-page ids equal
45
+ # the link anchors; non-split stored members keep their stored
46
+ # ids untouched. (@nested is the pre-split sectionsplit pass;
47
+ # the render loop's own pass over a sectionsplit parent is
48
+ # discarded, so it needs no suffix handling.)
49
+ @files.swap_document_suffix(docid, xml)
50
+ end
38
51
  # post: every @id/@anchor namespaced with this doc's NCName suffix, so
39
52
  # concatenated documents do not collide.
40
53
  @nested or update_sectionsplit_refs_to_docs(xml, docid, internal_refs,
@@ -55,6 +55,92 @@ module Metanorma
55
55
  end
56
56
  end
57
57
 
58
+ # Re-key an attribute value from one document suffix to another:
59
+ # a value ending "_#{from}" keeps its base and ends "_#{to}"
60
+ # instead, and a value carrying neither suffix gets "_#{to}".
61
+ # Mirror of add_suffix_to_attrs for documents whose ids were keyed
62
+ # by a previous build's suffix.
63
+ def swap_suffix_to_attrs(doc, suffixes, tag, attr, isodoc)
64
+ from, to = suffixes
65
+ suffix_swap?(from, to) or return
66
+ doc.xpath(isodoc.ns("//#{tag}[@#{attr}]" \
67
+ "[not(ancestor-or-self::*[local-name()='svg'])]"))
68
+ .each do |elem|
69
+ a = elem.attributes[attr].value
70
+ elem.attributes[attr].value = swap_suffix_value(a, from, to)
71
+ end
72
+ end
73
+
74
+ def swap_suffix_value(value, from, to)
75
+ value = value.sub(/_#{Regexp.escape(from)}\z/, "")
76
+ /_#{Regexp.escape(to)}$/.match?(value) or value = "#{value}_#{to}"
77
+ value
78
+ end
79
+
80
+ # Re-key id references in CSS (style attributes and style elements,
81
+ # outside SVGs) from one document suffix to another. Mirror of
82
+ # update_ids_css for documents keyed by a previous build's suffix.
83
+ def swap_ids_css(document, ids, from, to)
84
+ suffix_swap?(from, to) or return
85
+ document.xpath(".//m:style[not(ancestor::i:svg)]",
86
+ "m" => SVG_NS, "i" => SVG_NS).each do |s|
87
+ s.children = swap_ids_css_string(s.children.to_xml, ids, from, to)
88
+ end
89
+ document.xpath(".//*[@style][not(ancestor::i:svg)]",
90
+ "i" => SVG_NS).each do |s|
91
+ s["style"] = swap_ids_css_string(s["style"], ids, from, to)
92
+ end
93
+ end
94
+
95
+ # Re-key id references inside a string: every "<id>_#{from}" token
96
+ # whose base is a known id (in "#id" url references, "[id='…']"
97
+ # selectors, or bare attribute values) becomes "<id>_#{to}".
98
+ # Single pass over the string; `ids` maps base ids to true.
99
+ def swap_ids_css_string(style, ids, from, to)
100
+ return style unless style.include?("_#{from}")
101
+
102
+ from_re = Regexp.escape(from)
103
+ style.gsub(%r(\b([\w.:-]+)_#{from_re}\b)) do
104
+ base = Regexp.last_match(1)
105
+ ids.include?(base) or next Regexp.last_match(0)
106
+ "#{base}_#{to}"
107
+ end
108
+ end
109
+
110
+ # Re-key standalone SVG ids and their internal CSS from one
111
+ # document suffix to another. Mirror of the Vectory leg of
112
+ # url_in_css_styles for documents keyed by a previous build.
113
+ def swap_svg_ids(doc, ids, from, to)
114
+ suffix_swap?(from, to) or return
115
+ doc.xpath("//i:svg[not(ancestor::*[local-name()='svgmap'])]",
116
+ "i" => SVG_NS).each do |svg|
117
+ swap_svg_ids1(svg, ids, from, to)
118
+ end
119
+ end
120
+
121
+ def swap_svg_ids1(svg, ids, from, to)
122
+ svg.xpath(". | .//*[@*]").each do |n|
123
+ n.attribute_nodes.each do |x|
124
+ x.value = swap_ids_css_string(x.value, ids, from, to)
125
+ end
126
+ end
127
+ swap_svg_css(svg, ids, from, to)
128
+ end
129
+
130
+ def swap_svg_css(svg, ids, from, to)
131
+ svg.xpath(".//m:style", "m" => SVG_NS).each do |st|
132
+ st.children = swap_ids_css_string(st.children.to_xml, ids,
133
+ from, to)
134
+ end
135
+ svg.xpath(".//*[@style]").each do |n|
136
+ n["style"] = swap_ids_css_string(n["style"], ids, from, to)
137
+ end
138
+ end
139
+
140
+ def suffix_swap?(from, to)
141
+ !(from.nil? || from.empty? || from == to)
142
+ end
143
+
58
144
  def hash_key_detect(directives, key, variable)
59
145
  c = directives.detect { |x| x.key == key } or
60
146
  return variable
@@ -7,14 +7,28 @@ module Metanorma
7
7
  options&.dig(:require)&.each { |r| require r }
8
8
  end
9
9
 
10
+ OUTPUT_EXTENSIONS_XPATH =
11
+ "/*/*[local-name()='metanorma-extension']/" \
12
+ "*[local-name()='presentation-metadata']/" \
13
+ "*[local-name()='output-extensions']".freeze
14
+
10
15
  def extract_xml_options(file)
11
16
  xml = Nokogiri::XML(file, &:huge)
12
- if xml.root
13
- @registry.root_tags.each do |k, v|
14
- return { type: k } if v == xml.root.name
15
- end
16
- end
17
- {}
17
+ xml.root or return {}
18
+ # Keys are set only when present: options_in_file merges this hash
19
+ # over the AsciiDoc header options, and an absent key must not
20
+ # clear them.
21
+ { type: xml_root_type(xml), extensions: xml_output_extensions(xml) }
22
+ .compact
23
+ end
24
+
25
+ def xml_root_type(xml)
26
+ @registry.root_tags.find { |_, v| v == xml.root.name }&.first
27
+ end
28
+
29
+ def xml_output_extensions(xml)
30
+ ext = xml.at(OUTPUT_EXTENSIONS_XPATH)&.text&.strip
31
+ ext unless ext.nil? || ext.empty?
18
32
  end
19
33
 
20
34
  def extract_options(filename, options)
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "2.5.13".freeze
2
+ VERSION = "2.5.15".freeze
3
3
  end
data/metanorma.gemspec CHANGED
@@ -43,4 +43,4 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency "metanorma-iso"
44
44
 
45
45
  # relaton-cli is required by Metanorma::Collection
46
- spec.add_dependency "relaton-cli", "~> 3.0"end
46
+ spec.add_dependency "relaton", "~> 3.0"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.13
4
+ version: 2.5.15
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-04 00:00:00.000000000 Z
11
+ date: 2026-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -207,7 +207,7 @@ dependencies:
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: relaton-cli
210
+ name: relaton
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"