metanorma-utils 1.11.2 → 1.11.3

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: fb7eb442187f8f1129b1e5e0a6ae9e05f504522cb55c2a3f75b784fc803717cf
4
- data.tar.gz: 6819e04fc69ba93d601ce0053905db9ab10cea6d1e4af39e51a6d3b283603c02
3
+ metadata.gz: bb5a317fefc85b76b0442eadf4805403c76e68384b9ea22685941442db330a3f
4
+ data.tar.gz: 01cf01d1d045ab721fdba705d79757af0e18dd025f67f070731a7029f1736c1e
5
5
  SHA512:
6
- metadata.gz: f21d1d2c7431b3de60715d50848d1a9ae6314c0dce3918a4db1d020e81928fff965148c8de4865186ab470e2242f775d35184ea212aa9c96f988a9ee32fc06bf
7
- data.tar.gz: cc86b4e88d4cb126ac2d7824a996341db7194724ff95242bf17f4d2743a56552bb01486fb122e674901012cfe6a7f361acba60dd9504b98af7b8a8f7bbf3dbb8
6
+ metadata.gz: be7834de49cb96791995188b265fb1cf97fa29366ff367931007ea4101233aa16317f5a31e4b4cb837b9ea6418f92c68df0848575d3ba6b3fce8e50c072e9571
7
+ data.tar.gz: 2f2b23b525347b8cb07d2cba54376685357c1ef1b2d78120504f91e91fa10eef1c0298cf5c4ef03ef1e97ee43d9ac9340b4c2657d2196980dfd548ee1b4f7a94
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.11.2".freeze
3
+ VERSION = "1.11.3".freeze
4
4
  end
5
5
  end
data/lib/utils/xml.rb CHANGED
@@ -40,6 +40,41 @@ module Metanorma
40
40
  (ret1 || "") + ret2.gsub(%r([#{NAMECHAR}#])o, "_")
41
41
  end
42
42
 
43
+ # Following XML requirements: https://www.w3.org/TR/REC-xml/#NT-Name
44
+ TAG_NAME_START_CODEPOINTS = "@:A-Z_a-z\u{C0}-\u{D6}\u{D8}-\u{F6}\u{F8}-\u{2FF}\u{370}-\u{37D}\u{37F}-\u{1FFF}" \
45
+ "\u{200C}-\u{200D}\u{2070}-\u{218F}\u{2C00}-\u{2FEF}\u{3001}-\u{D7FF}\u{F900}-\u{FDCF}" \
46
+ "\u{FDF0}-\u{FFFD}\u{10000}-\u{EFFFF}"
47
+ INVALID_TAG_NAME_START_REGEXP = /[^#{TAG_NAME_START_CODEPOINTS}]/
48
+ TAG_NAME_FOLLOWING_CODEPOINTS = "#{TAG_NAME_START_CODEPOINTS}\\-.0-9\u{B7}\u{0300}-\u{036F}\u{203F}-\u{2040}"
49
+ INVALID_TAG_NAME_FOLLOWING_REGEXP = /[^#{TAG_NAME_FOLLOWING_CODEPOINTS}]/
50
+ SAFE_XML_TAG_NAME_REGEXP = /\A[#{TAG_NAME_START_CODEPOINTS}][#{TAG_NAME_FOLLOWING_CODEPOINTS}]*\z/
51
+ TAG_NAME_REPLACEMENT_CHAR = "_"
52
+
53
+ # from: https://github.com/rails/rails/blob/3235827585d87661942c91bc81f64f56d710f0b2/activesupport/lib/active_support/core_ext/erb/util.rb
54
+ # A utility method for escaping XML names of tags and names of attributes.
55
+ #
56
+ # xml_name_escape('1 < 2 & 3')
57
+ # # => "1___2___3"
58
+ #
59
+ # It follows the requirements of the specification: https://www.w3.org/TR/REC-xml/#NT-Name
60
+ def to_ncname(name, asciionly: true)
61
+ name = name.to_s
62
+ return "" if name.nil? || name.empty?
63
+ return name if name.match?(SAFE_XML_TAG_NAME_REGEXP)
64
+
65
+ starting_char = name[0]
66
+ starting_char.gsub!(INVALID_TAG_NAME_START_REGEXP,
67
+ TAG_NAME_REPLACEMENT_CHAR)
68
+
69
+ return starting_char if name.size == 1
70
+
71
+ following_chars = name[1..-1]
72
+ following_chars.gsub!(INVALID_TAG_NAME_FOLLOWING_REGEXP,
73
+ TAG_NAME_REPLACEMENT_CHAR)
74
+
75
+ starting_char << following_chars
76
+ end
77
+
43
78
  def anchor_or_uuid(node = nil)
44
79
  uuid = UUIDTools::UUID.random_create
45
80
  node.nil? || node.id.nil? || node.id.empty? ? "_#{uuid}" : node.id
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: 1.11.2
4
+ version: 1.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-17 00:00:00.000000000 Z
11
+ date: 2025-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor