metanorma-standoc 3.5.32 → 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: '036370981e7443661c8562d25ce5f82ddeebda8475db456ac69865e48de95e0c'
4
- data.tar.gz: 0b862e9aa1360debf9a5dce02094a1c045126f6004b0fbdc32ae834b6089099e
3
+ metadata.gz: 9664ff688dec6f5eb53bbf1780508811a7ff5594cb02bf07d203da99722e964c
4
+ data.tar.gz: 34d8e3ca4f387ac093fff60264a30a93c96c581157dc9b27ecf08bf2cdab66ad
5
5
  SHA512:
6
- metadata.gz: 0fb574fd098a998360dfd31a2004b376dbffe9869c9e46b4ae81c93ec83476abfb91b01ae13ae841f4aea145ee4486879b7a140f52d763b925f624545f0f7f0d
7
- data.tar.gz: 4bd4b82c9566e4470b76cec9ef54fc26c8836d328ff095e81eaa9f1a1b3d5b1294f19132273ff04191776d024438956170a68854d1fb97cecb807d6ea1fb7f22
6
+ metadata.gz: 6a8eceae780cdce07c4227da4e583db6edba750b5f278985fcf46218e9024ab064981705cec8a116fb95bb6a5b864bc478b0b7130e3c9b6a824d65a3af1d4a1b
7
+ data.tar.gz: 69d777a8b9a8cba904e6eba7e35732757a48bcc329f08de021fa5d6781814d0275955435fc3352f76f57c928fde3b1fa6071033a0dfd97d87c9ebbf1b29a6ace
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "3.5.32".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
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.32
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-26 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