metanorma-utils 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 717014b944b65d1e4f5b7c7ed0c71b3ac3314a3fb9ac740ff0027e9b5088cea8
4
- data.tar.gz: c5bc40281e230a272deaf0469d4b9b6dd85e4f6b124de1e64d4c5c16347b2e8c
3
+ metadata.gz: bdf1c0f7c6fc507ad433fe2050575ce055f637d14be8d8422841aa562c710b71
4
+ data.tar.gz: 1492564fdf19ecdea102ec3042f38222ae1c495d33ccc07db74d40312d01be66
5
5
  SHA512:
6
- metadata.gz: ef77c94f8be1071eead01e24fdbdbf1367ea2fc19ede7f1b3bf0149127863e38d56fea39a42a4685b3c65112431c251fab1507602a54b0307dae108a7ab563c9
7
- data.tar.gz: 6a86994cc199526918abbb80cb79f0c099a3aa2eb3480b4d763e381a351cea0184ccce285eef28b49cb9d441037469ea4f21df91258a3b09c64bc889c76bf80f
6
+ metadata.gz: c20276334e3ae738d797f823d809d45242677571f0b1746af012b08789b2da879877eb96f3196639fdc80ca1aa880294462cb07a3f36dbd91b20e8940fd84b0e
7
+ data.tar.gz: 6339006703fe2e0fc338a06a5c55b5b7c38bbc899623a16b22deb18fac01967db131e7b8888fab7388a710dfda658d51db0ce76d8556285c01a54616f034ba2b
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.9.0".freeze
3
+ VERSION = "1.10.0".freeze
4
4
  end
5
5
  end
data/lib/utils/xml.rb CHANGED
@@ -48,49 +48,37 @@ module Metanorma
48
48
  # block for processing XML document fragments as XHTML,
49
49
  # to allow for HTMLentities
50
50
  # Unescape special chars used in Asciidoctor substitution processing
51
- def noko(script = "Latn", &block)
52
- doc = ::Nokogiri::XML.parse(NOKOHEAD)
53
- fragment = doc.fragment("")
54
- ::Nokogiri::XML::Builder.with fragment, &block
55
- eoln = %w(Hans Hant Jpan).include?(script) ? "" : " "
56
- fragment.to_xml(encoding: "US-ASCII", indent: 0,
57
- save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
58
- .lines.map do |l|
59
- l.gsub(/>\n$/, ">").gsub(/\n$/m, eoln).gsub("–", "\u0096")
60
- .gsub("—", "\u0097").gsub("–", "\u0096")
61
- .gsub("—", "\u0097")
62
- end
63
- end
64
-
65
51
  def noko(_script = "Latn", &block)
66
52
  fragment = ::Nokogiri::XML.parse(NOKOHEAD).fragment("")
67
53
  ::Nokogiri::XML::Builder.with fragment, &block
68
- ret = fragment
54
+ fragment
69
55
  .to_xml(encoding: "UTF-8", indent: 0,
70
56
  save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
71
- .lines.map do |l|
72
- l.rstrip.gsub("–", "\u0096").gsub("—", "\u0097")
73
- .gsub("–", "\u0096").gsub("—", "\u0097")
74
- end
75
- line_sanitise(ret)
57
+ .gsub("–", "\u0096").gsub("—", "\u0097")
58
+ .gsub("–", "\u0096").gsub("—", "\u0097")
76
59
  end
77
60
 
78
61
  # By default, carriage return in source translates to whitespace;
79
- # but in CJK, it does not. We don't want carriage returns in the final
80
- # output because of CJK complications
62
+ # but in CJK, it does not. (Non-CJK text \n CJK)
81
63
  def line_sanitise(ret)
82
64
  ret.size == 1 and return ret
83
- (0...ret.size).each do |i|
65
+ (0...(ret.size - 1)).each do |i|
84
66
  last = firstchar_xml(ret[i].reverse)
85
67
  nextfirst = firstchar_xml(ret[i + 1])
86
- /#{CJK}/o.match?(last) && /#{CJK}/o.match?(nextfirst) or
87
- ret[i] += " "
68
+ cjk1 = /#{CJK}/o.match?(last)
69
+ cjk2 = /#{CJK}/o.match?(nextfirst)
70
+ text1 = /[^\p{Z}\p{C}]/.match?(last)
71
+ text2 = /[^\p{Z}\p{C}]/.match?(nextfirst)
72
+ (cjk1 && (cjk2 || !text2)) and next
73
+ !text1 && cjk2 and next
74
+ ret[i] += " "
88
75
  end
89
76
  ret
90
77
  end
91
78
 
79
+ # need to deal with both <em> and its reverse string, >me<
92
80
  def firstchar_xml(line)
93
- m = /^(<[^>]+>)*(.)/.match(line) or return ""
81
+ m = /^([<>][^<>]+[<>])*(.)/.match(line) or return ""
94
82
  m[2]
95
83
  end
96
84
 
@@ -46,5 +46,6 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency "timecop", "~> 0.9"
47
47
  spec.add_development_dependency "vcr", "~> 6.1.0"
48
48
  spec.add_development_dependency "webmock"
49
+ spec.add_development_dependency "xml-c14n"
49
50
  #spec.metadata["rubygems_mfa_required"] = "true"
50
51
  end
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.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-21 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -276,6 +276,20 @@ dependencies:
276
276
  - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
+ - !ruby/object:Gem::Dependency
280
+ name: xml-c14n
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '0'
279
293
  description: 'metanorma-utils provides utilities for the Metanorma stack
280
294
 
281
295
  '