metanorma-utils 2.0.9 → 2.0.11

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: '07949ed48f399c7f876d5eb10e186d0337e4ce69300440be94868b45dc56e863'
4
- data.tar.gz: 2879b5d318dffc0782334e8c0520e821ef01e095ae4c3727c9e38ae4f48ed32e
3
+ metadata.gz: 4bf5d712d55cb73ba43cc6bfc97814fc8dd56989afc9ab8abbacf38d58f620e1
4
+ data.tar.gz: 210beeb0bf946b01fbcfbd3db0bb6845322e6c58e4fb134471bf9e714eb6b2ea
5
5
  SHA512:
6
- metadata.gz: 62080c3912b5094a041343de87f4bfc74a893b46ba0c81c7b9b3c1a696d73bfc513a353cf577e9800b8f49b896a6176ee870b8eecf25bf4db11edab18a117d20
7
- data.tar.gz: df3a81407eb5e0d8b2cdd9f6faec0b1f54558bb90e24575de23d1cee38ffa09e289373b8a680b8f88597e43fb54a171d1714dccca6716ef4336804c0a308e21b
6
+ metadata.gz: bc01cd86992bfe05030beca1094025f04cd64110fa3b896c718a3a8f0ca16ac1883128ad6e97747011c53d075849ff6c4b8b5c7996d35cf081321e5bf19eaa8d
7
+ data.tar.gz: 28950533206989b2bdb78b5d88b79df3cc9a491f8a1d01f96f91841ce230f83bf9e435795dff082e96d7d6d3d2139f96e43e77c57ea3adccf7c0d1e0e2de7bf6
@@ -7,5 +7,7 @@ require_relative "utils/log"
7
7
  require_relative "utils/xml"
8
8
  require_relative "utils/anchor"
9
9
  require_relative "utils/anchor_ranges"
10
+ require_relative "utils/random_uuid"
11
+ require_relative "utils/htmlentities_patch"
10
12
  require_relative "utils/gc_budget"
11
13
  require_relative "utils/asciidoctor_table_buffer"
@@ -87,17 +87,16 @@ module Metanorma
87
87
  # @return [String, nil] The anchor attribute of the next non-descendant node
88
88
  def find_next_non_descendant_anchor(nodes, current_index)
89
89
  current_node = nodes[current_index]
90
- current_path = current_node.path
91
90
 
92
91
  # Look through subsequent nodes
93
92
  ((current_index + 1)...nodes.length).each do |i|
94
93
  next_node = nodes[i]
95
- next_path = next_node.path
96
94
 
97
- # Check if next_node is a descendant of current_node
98
- # A node is a descendant if its path starts with the current path
99
- # followed by a path separator
100
- unless next_path.start_with?("#{current_path}/")
95
+ # Check if next_node is a descendant of current_node. A path
96
+ # prefix comparison would construct every node's libxml path
97
+ # string (a measured hot spot on large documents); the parent
98
+ # walk answers the same question without building strings.
99
+ unless node_is_descendant?(next_node, current_node)
101
100
  return next_node["anchor"]
102
101
  end
103
102
  end
@@ -105,6 +104,16 @@ module Metanorma
105
104
  nil # No non-descendant node found
106
105
  end
107
106
 
107
+ def node_is_descendant?(node, ancestor)
108
+ parent = node.parent
109
+ while parent && parent.element?
110
+ return true if parent == ancestor
111
+
112
+ parent = parent.parent
113
+ end
114
+ false
115
+ end
116
+
108
117
  def build_anchor_to_ord
109
118
  hash = {}
110
119
  @anchor_map.each do |entry|
@@ -0,0 +1,22 @@
1
+ require "htmlentities"
2
+
3
+ module Metanorma
4
+ module Utils
5
+ # htmlentities constructs a fresh Encoder — with its encoding procs —
6
+ # on every #encode call. Cleanup and smart-quote processing encode per
7
+ # text node on document-scale compiles, so the rebuilds were a
8
+ # measured hot spot. The Encoder is deterministic per (flavor,
9
+ # instruction set) and stateless across encodes, so one encoder per
10
+ # instruction set can be reused.
11
+ module HTMLEntitiesEncoderCache
12
+ def encode(source, *instructions)
13
+ key = instructions.empty? ? [:basic] : instructions
14
+ cache = (@metanorma_encoder_cache ||= {})
15
+ (cache[key] ||= ::HTMLEntities::Encoder.new(@flavor, key))
16
+ .encode(source)
17
+ end
18
+ end
19
+
20
+ ::HTMLEntities.prepend(HTMLEntitiesEncoderCache)
21
+ end
22
+ end
data/lib/utils/log.rb CHANGED
@@ -13,7 +13,7 @@ module Metanorma
13
13
  @c = HTMLEntities.new
14
14
  @mapid = {}
15
15
  @suppress_log = { severity: 4, category: [], error_ids: [],
16
- locations: [] }
16
+ error_regexes: [], locations: [] }
17
17
  @msg = messages.each_value do |v|
18
18
  v[:error] = v[:error]
19
19
  .encode("UTF-8", invalid: :replace, undef: :replace)
@@ -49,6 +49,8 @@ module Metanorma
49
49
  def add(id, loc, display: true, params: [])
50
50
  m = add_prep(id) or return
51
51
  msg = create_entry(loc, m[:error], m[:severity], id, params)
52
+ return if suppressed_message?(msg[:error])
53
+
52
54
  @log[m[:category]] << msg
53
55
  loc = loc.nil? ? "" : "(#{current_location(loc)[0]}): "
54
56
  suppress_display?(m[:category], loc, msg, display) or
@@ -79,6 +81,13 @@ module Metanorma
79
81
  @suppress_log[:error_ids].include?(id.to_s)
80
82
  end
81
83
 
84
+ # Message-text suppressions (`log-filter-error-regex`): drop entries
85
+ # whose interpolated message matches any pattern, without suppressing
86
+ # the other messages sharing the same code.
87
+ def suppressed_message?(text)
88
+ Array(@suppress_log[:error_regexes]).any? { |re| re.match?(text) }
89
+ end
90
+
82
91
  def suppress_display?(category, _loc, _msg, display)
83
92
  ["Metanorma XML Syntax", "Relaton"].include?(category) ||
84
93
  !display
@@ -0,0 +1,31 @@
1
+ require "securerandom"
2
+
3
+ module Metanorma
4
+ module Utils
5
+ # Entropy buffer for identifier generation: document compiles create
6
+ # hundreds of thousands of random identifiers, and an OS entropy read
7
+ # per identifier dominated compile CPU. Draw from a pooled SecureRandom
8
+ # block instead, refilled as it drains.
9
+ RAND_POOL_BYTES = 65_536
10
+
11
+ @rand_pool = +""
12
+ @rand_pool_mutex = Mutex.new
13
+
14
+ class << self
15
+ def random_uuid
16
+ bytes = @rand_pool_mutex.synchronize do
17
+ if @rand_pool.bytesize < 16
18
+ @rand_pool = SecureRandom.random_bytes(RAND_POOL_BYTES)
19
+ end
20
+ @rand_pool.byteslice(0, 16)
21
+ .tap { @rand_pool = @rand_pool.byteslice(16..) }
22
+ end
23
+
24
+ bytes.setbyte(6, (bytes.getbyte(6) & 0x0f) | 0x40)
25
+ bytes.setbyte(8, (bytes.getbyte(8) & 0x3f) | 0x80)
26
+ hex = bytes.unpack1("H32")
27
+ "#{hex[0, 8]}-#{hex[8, 4]}-#{hex[12, 4]}-#{hex[16, 4]}-#{hex[20, 12]}"
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "2.0.9".freeze
3
+ VERSION = "2.0.11".freeze
4
4
  end
5
5
  end
@@ -37,7 +37,6 @@ Gem::Specification.new do |spec|
37
37
 
38
38
  spec.add_development_dependency "bundler"
39
39
  spec.add_development_dependency "debug"
40
- spec.add_development_dependency "equivalent-xml", "~> 0.6"
41
40
  spec.add_development_dependency "guard", "~> 2.14"
42
41
  spec.add_development_dependency "guard-rspec", "~> 4.7"
43
42
  spec.add_development_dependency "rake", "~> 13.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.11
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-30 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
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: equivalent-xml
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.6'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.6'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: guard
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -326,12 +312,14 @@ files:
326
312
  - lib/utils/cjk.rb
327
313
  - lib/utils/gc_budget.rb
328
314
  - lib/utils/hash_transform_keys.rb
315
+ - lib/utils/htmlentities_patch.rb
329
316
  - lib/utils/image.rb
330
317
  - lib/utils/linestatus.rb
331
318
  - lib/utils/log.rb
332
319
  - lib/utils/log_html.rb
333
320
  - lib/utils/main.rb
334
321
  - lib/utils/namespace.rb
322
+ - lib/utils/random_uuid.rb
335
323
  - lib/utils/version.rb
336
324
  - lib/utils/xml.rb
337
325
  - metanorma-utils.gemspec