metanorma-standoc 3.5.31 → 3.5.33

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: c2d7915082c5cae65f0681e72ac3815bbcfd88df1102fc1079f28decbd894821
4
- data.tar.gz: 521849313742749ba454b7cb28405a7515b0c22206a26f6785dc1b36c7e02d12
3
+ metadata.gz: 9664ff688dec6f5eb53bbf1780508811a7ff5594cb02bf07d203da99722e964c
4
+ data.tar.gz: 34d8e3ca4f387ac093fff60264a30a93c96c581157dc9b27ecf08bf2cdab66ad
5
5
  SHA512:
6
- metadata.gz: 8d6074cadae2db8fd2c0100dbc810f8ba5e6e6fa6d9cc7c82bb80f875d8dc37b83e67ae6405b155721489e53f2cb07c475041059356c96167e5454fa5c7a2df9
7
- data.tar.gz: cbf8d42004aacef8246c7f82940e6a433cc84a95ca5e1a6a800cbfe67821d0ae56c073b99afcceab4e9efc90a9830319ad2a83b0346e3a6efc5a80549a10fea6
6
+ metadata.gz: 6a8eceae780cdce07c4227da4e583db6edba750b5f278985fcf46218e9024ab064981705cec8a116fb95bb6a5b864bc478b0b7130e3c9b6a824d65a3af1d4a1b
7
+ data.tar.gz: 69d777a8b9a8cba904e6eba7e35732757a48bcc329f08de021fa5d6781814d0275955435fc3352f76f57c928fde3b1fa6071033a0dfd97d87c9ebbf1b29a6ace
@@ -155,7 +155,8 @@ module Metanorma
155
155
  @fn_number ||= 0
156
156
  noko do |xml|
157
157
  @fn_number += 1
158
- xml.fn **attr_code(id_attr(nil).merge(reference: @fn_number)) do |fn|
158
+ xml.fn **attr_code(id_attr(nil, seed: "footnote-#{@fn_number}")
159
+ .merge(reference: @fn_number)) do |fn|
159
160
  fn.p { |p| p << node.text }
160
161
  end
161
162
  end
@@ -6,15 +6,45 @@ require_relative "blocks_image"
6
6
  module Metanorma
7
7
  module Standoc
8
8
  module Blocks
9
- def id_attr(node = nil)
9
+ def id_attr(node = nil, seed: nil)
10
10
  anchor = node&.id
11
- { id: "_#{Metanorma::Utils.random_uuid}",
11
+ { id: "_#{stable_block_id(node, seed: seed)}",
12
12
  anchor: anchor && !anchor.empty? ? anchor : nil,
13
13
  tag: node&.attr("tag"), columns: node&.attr("columns"),
14
14
  "multilingual-rendering": node&.attr("multilingual-rendering") }
15
15
  .compact
16
16
  end
17
17
 
18
+ # Deterministic ids for anchor-less elements (isodoc#861): the
19
+ # document identity, the element's text (or an explicit seed),
20
+ # and the occurrence ordinal of that text mint a stable UUIDv5 -
21
+ # a recompile produces the same ids, where the random mint made
22
+ # every compile's HTML carry different heading and term ids and
23
+ # the TOC links moved with them. Elements carrying nothing
24
+ # seedable keep the random mint.
25
+ def stable_block_id(node, seed: nil)
26
+ text = seed || stable_seed_text(node)
27
+ return Metanorma::Utils.random_uuid if text.empty?
28
+
29
+ key = [document_seed(node), text]
30
+ @stable_id_counts ||= Hash.new(0)
31
+ Metanorma::Utils.stable_uuid(*key, @stable_id_counts[key] += 1)
32
+ end
33
+
34
+ # Sections carry a title, blocks a text; either seeds the mint.
35
+ def stable_seed_text(node)
36
+ t = node.respond_to?(:title) ? node.title.to_s.strip : ""
37
+ t = node.text.to_s.strip if t.empty? && node.respond_to?(:text)
38
+ t.strip
39
+ end
40
+
41
+ # The basename only: the same source compiled in another
42
+ # directory must produce the same ids, so the seed stays free of
43
+ # the build machine's paths.
44
+ def document_seed(node)
45
+ File.basename(node&.document&.attributes&.[]("docfile").to_s)
46
+ end
47
+
18
48
  def id_unnum_attrs(node)
19
49
  attr_code(id_attr(node).merge(
20
50
  unnumbered: node.option?("unnumbered") ? "true" : nil,
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.5.31".freeze
22
+ VERSION = "3.5.33".freeze
23
23
  end
24
24
  end
@@ -1,6 +1,8 @@
1
1
  require "leptris"
2
2
  require "leptris/xml/relaxng"
3
3
  require "tempfile"
4
+ require "fileutils"
5
+ require "pathname"
4
6
 
5
7
  module Metanorma
6
8
  module Standoc
@@ -28,11 +30,76 @@ module Metanorma
28
30
  end
29
31
 
30
32
  def schema_validate_errors(schema, file_path)
31
- rng = Leptris::XML::RelaxNG.parse_file(schema)
33
+ rng = compiled_schema_rng(schema)
32
34
  doc = Leptris::XML.parse(File.read(file_path), readonly: true)
33
35
  rng.validate_errors(doc)
34
36
  end
35
37
 
38
+ # The packed toolchain serves gem files from a memfs that the
39
+ # native file layer cannot see: parse_file opens the path
40
+ # through libleptris and dies with "cannot open schema file
41
+ # 'A:/...'" (tebako, metanorma-standoc#1416), while bare
42
+ # RelaxNG.parse cannot compile a schema that uses <include>
43
+ # ("include ...: no base URI"). Materialize the schema and its
44
+ # include closure through Ruby IO into a real directory - each
45
+ # href resolves against its own source file's directory, and
46
+ # the staged tree mirrors that geometry - and compile from
47
+ # there.
48
+ def compiled_schema_rng(schema_path)
49
+ expanded = File.expand_path(schema_path)
50
+ unless File.file?(expanded)
51
+ # A missing or unreadable schema fails the way it always
52
+ # has (the clean-abort contract): parse_file raises on the
53
+ # original path.
54
+ return Leptris::XML::RelaxNG.parse_file(schema_path)
55
+ end
56
+
57
+ Dir.mktmpdir(["metanorma_rng"]) do |dir|
58
+ staged = stage_schema_closure(expanded, dir)
59
+ Leptris::XML::RelaxNG.parse_file(staged)
60
+ end
61
+ end
62
+
63
+ def stage_schema_closure(schema_path, dir)
64
+ top_dir = File.dirname(schema_path)
65
+ staged = File.join(dir, File.basename(schema_path))
66
+ FileUtils.mkdir_p(File.dirname(staged))
67
+ FileUtils.cp(schema_path, staged)
68
+ copy_include_closure(schema_path, top_dir, dir)
69
+ staged
70
+ end
71
+
72
+ def copy_include_closure(source, top_dir, dir)
73
+ pending = [source]
74
+ visited = []
75
+ until pending.empty?
76
+ src = pending.pop
77
+ next if visited.include?(src)
78
+
79
+ visited << src
80
+ hrefs(src).each do |href|
81
+ next if href.start_with?("http:", "https:", "file:", "/")
82
+
83
+ target = File.expand_path(href, File.dirname(src))
84
+ next unless File.file?(target)
85
+
86
+ stage_include_target(target, top_dir, dir)
87
+ pending << target
88
+ end
89
+ end
90
+ end
91
+
92
+ def stage_include_target(target, top_dir, dir)
93
+ rel = Pathname.new(target).relative_path_from(Pathname.new(top_dir))
94
+ staged = File.join(dir, rel.to_s)
95
+ FileUtils.mkdir_p(File.dirname(staged))
96
+ FileUtils.cp(target, staged) unless File.exist?(staged)
97
+ end
98
+
99
+ def hrefs(path)
100
+ File.read(path).scan(/href="([^"]+)"/).flatten
101
+ end
102
+
36
103
  def schema_validate1(file, doc, schema)
37
104
  file.write(to_xml(doc))
38
105
  file.close
@@ -40,7 +40,9 @@ Gem::Specification.new do |spec|
40
40
  # LutamlJsonschemaPreprocessor shipped in 0.7.74
41
41
  spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7", ">= 0.7.74"
42
42
  spec.add_dependency "metanorma-plugin-plantuml", "~> 1.0.0"
43
- spec.add_dependency "metanorma-utils", "~> 2.0.12"
43
+ # >= 2.0.13: Metanorma::Utils.stable_uuid - the deterministic
44
+ # anchor-less element id mint (isodoc#861).
45
+ spec.add_dependency "metanorma-utils", "~> 2.0.13"
44
46
  # moxml 0.6.0 removed the Opal surface (lutaml/moxml#516); owner
45
47
  # call to update all to the latest moxml line.
46
48
  spec.add_dependency "moxml", "~> 0.6.1"
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.31
4
+ version: 3.5.33
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-25 00:00:00.000000000 Z
11
+ date: 2026-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -162,14 +162,14 @@ dependencies:
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 2.0.12
165
+ version: 2.0.13
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: 2.0.12
172
+ version: 2.0.13
173
173
  - !ruby/object:Gem::Dependency
174
174
  name: moxml
175
175
  requirement: !ruby/object:Gem::Requirement