metanorma-utils 2.0.9 → 2.0.10
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 +4 -4
- data/lib/metanorma-utils.rb +2 -0
- data/lib/utils/anchor_ranges.rb +15 -6
- data/lib/utils/htmlentities_patch.rb +22 -0
- data/lib/utils/random_uuid.rb +31 -0
- data/lib/utils/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e1ddc1c3756df2bcc60f9e0f0086c1b9d155d87f7c2610649258072cad752c90
|
|
4
|
+
data.tar.gz: a1641beae7017d40c84f5e467bf1ae82622647c365330eedd59a263969b05543
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 789580fa0a6930a00fb2e516ade31277881889e16a6f6e821d602d14bed3d7a08b91d23a57ccfbf91622727d66e447ede7df85300bddac5c0f13e3f23b5a0713
|
|
7
|
+
data.tar.gz: 4408944cfc83ae85cbd57d4b839bf0afd0d2697c9b34442ec666ba2338fa2865f933d49fcfe5eaf0c21710cdb5fbd96b792edfc03dde03260c04dcfcf7ccb4a9
|
data/lib/metanorma-utils.rb
CHANGED
|
@@ -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"
|
data/lib/utils/anchor_ranges.rb
CHANGED
|
@@ -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
|
-
#
|
|
99
|
-
#
|
|
100
|
-
|
|
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
|
|
@@ -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
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.
|
|
4
|
+
version: 2.0.10
|
|
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-
|
|
11
|
+
date: 2026-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: asciidoctor
|
|
@@ -326,12 +326,14 @@ files:
|
|
|
326
326
|
- lib/utils/cjk.rb
|
|
327
327
|
- lib/utils/gc_budget.rb
|
|
328
328
|
- lib/utils/hash_transform_keys.rb
|
|
329
|
+
- lib/utils/htmlentities_patch.rb
|
|
329
330
|
- lib/utils/image.rb
|
|
330
331
|
- lib/utils/linestatus.rb
|
|
331
332
|
- lib/utils/log.rb
|
|
332
333
|
- lib/utils/log_html.rb
|
|
333
334
|
- lib/utils/main.rb
|
|
334
335
|
- lib/utils/namespace.rb
|
|
336
|
+
- lib/utils/random_uuid.rb
|
|
335
337
|
- lib/utils/version.rb
|
|
336
338
|
- lib/utils/xml.rb
|
|
337
339
|
- metanorma-utils.gemspec
|