metanorma-utils 1.9.0 → 1.10.1

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: fe2af0c9b9521b3ae1953545fb434d08e45d028dd93c02fa509a8251e14e1c8e
4
+ data.tar.gz: c551aa4d4c08dba83273ce0be945a171cfbbdc4a9a2c02fd09044b3c97a8b317
5
5
  SHA512:
6
- metadata.gz: ef77c94f8be1071eead01e24fdbdbf1367ea2fc19ede7f1b3bf0149127863e38d56fea39a42a4685b3c65112431c251fab1507602a54b0307dae108a7ab563c9
7
- data.tar.gz: 6a86994cc199526918abbb80cb79f0c099a3aa2eb3480b4d763e381a351cea0184ccce285eef28b49cb9d441037469ea4f21df91258a3b09c64bc889c76bf80f
6
+ metadata.gz: f6a23dde225425211a6ac35bb0e9b718189f0bc071eeef526a36ecebd3f8572f78addf7b93c4390374511642c360b6543e88e98e459ea1bb76849d077e008730
7
+ data.tar.gz: b537b6828491a4cc6f495c462e0c0810a8b1fcd61effb326232980f07325fe70e2ddc6b9f3c09d60b1f8c6af250c38e21064617acd294f8fa3542e141d647f40
@@ -29,7 +29,7 @@ module Metanorma
29
29
  @middoc_docattr = false
30
30
  @pass = false
31
31
  elsif (@is_delim && /^(--+|\*\*+|==+|__+)$/.match?(text)) ||
32
- (!@is_delim && !@delimln && /^-----*$|^\.\.\.\.\.*$|\/\/\/\/\/*$/
32
+ (!@is_delim && !@delimln && /^-----*$|^\.\.\.\.\.*$|^\/\/\/\/\/*$/
33
33
  .match?(text))
34
34
  @delimln = text
35
35
  @pass = true
data/lib/utils/log.rb CHANGED
@@ -91,7 +91,7 @@ module Metanorma
91
91
  if node.respond_to?(:line) && !node.line.nil?
92
92
  "#{'%06d' % node.line}"
93
93
  elsif /^XML Line /.match?(msg)
94
- msg.sub(/^XML Line /, "").sub(/:.*$/, "")
94
+ msg.sub(/^XML Line /, "").sub(/(^[^:]+):.*$/, "\\1")
95
95
  else
96
96
  "000000"
97
97
  end
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.1".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
 
@@ -111,15 +99,15 @@ module Metanorma
111
99
  end
112
100
 
113
101
  def ns(xpath)
114
- xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1")
115
- .gsub(%r{::([a-zA-z])}, "::xmlns:\\1")
116
- .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/-]* ?=)}, "[xmlns:\\1")
117
- .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/-]*[/\[\]])}, "[xmlns:\\1")
102
+ xpath.gsub(%r{/([a-zA-Z])}, "/xmlns:\\1")
103
+ .gsub(%r{::([a-zA-Z])}, "::xmlns:\\1")
104
+ .gsub(%r{\[([a-zA-Z][a-z0-9A-Z@/-]* ?=)}, "[xmlns:\\1")
105
+ .gsub(%r{\[([a-zA-Z][a-z0-9A-Z@/-]*[/\[\]])}, "[xmlns:\\1")
118
106
  end
119
107
 
120
108
  def numeric_escapes(xml)
121
109
  c = HTMLEntities.new
122
- xml.split(/(&[^ \r\n\t#;]+;)/).map do |t|
110
+ xml.split(/(&[^ \r\n\t#&;]+;)/).map do |t|
123
111
  if /^(&[^ \t\r\n#;]+;)/.match?(t)
124
112
  c.encode(c.decode(t), :hexadecimal)
125
113
  else t
@@ -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.1
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-22 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
  '