metanorma-utils 1.8.4 → 1.9.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: acea881df59c64c2137792a3fc9bbb5a36d09dd43fc5fa6d0e3b066b3bbb60da
4
- data.tar.gz: 00fc04e75a5eec309ed1a1d62633e7c9358e93adbf0558f12bad11fa069d4441
3
+ metadata.gz: 717014b944b65d1e4f5b7c7ed0c71b3ac3314a3fb9ac740ff0027e9b5088cea8
4
+ data.tar.gz: c5bc40281e230a272deaf0469d4b9b6dd85e4f6b124de1e64d4c5c16347b2e8c
5
5
  SHA512:
6
- metadata.gz: 2ba485eb93b52444caa930e05dc185f8506fc1d68c70483f43593e560e63ab418aeea60375e579363b120a7864046daefe4cd6ded9769491990748a88570cf83
7
- data.tar.gz: c16aecbe71a3acdede53591130d310f9745fc3b8d59a7624250d36ab93468a0f16ecc05b6251c10d6dac34bab792fd15fb0344a2cd30e606f4166b4d5ed045af
6
+ metadata.gz: ef77c94f8be1071eead01e24fdbdbf1367ea2fc19ede7f1b3bf0149127863e38d56fea39a42a4685b3c65112431c251fab1507602a54b0307dae108a7ab563c9
7
+ data.tar.gz: 6a86994cc199526918abbb80cb79f0c099a3aa2eb3480b4d763e381a351cea0184ccce285eef28b49cb9d441037469ea4f21df91258a3b09c64bc889c76bf80f
@@ -0,0 +1,22 @@
1
+ module Sterile
2
+ class << self
3
+ alias_method :old_smart_format_rules, :smart_format_rules
4
+ =begin
5
+ # what would replace the Sterile rules with more broadly applicable \{Zs}
6
+ [/(\p{Zs}|\A|"|\(|\[)'/, "\\1‘"],
7
+ [/(\S)'([^\'\p{Zs}])/, "\\1’\\2"],
8
+ [/(\p{Zs}|\A|\(|\[)"(?!\s)/, "\\1“\\2"],
9
+ [/"(\p{Zs}|\S|\Z)/, "”\\1"],
10
+ [/'([\p{Zs}.]|\Z)/, "’\\1"],
11
+ ] + old_smart_format_rules
12
+ =end
13
+ def smart_format_rules
14
+ [
15
+ [/(\S)'([^\'\p{Zs}])/, "\\1’\\2"],
16
+ [/(\p{Zs})"(?!\s)/, "\\1“\\2"],
17
+ [/"(\p{Zs})/, "”\\1"],
18
+ [/'([\p{Zs}.])/, "’\\1"],
19
+ ] + old_smart_format_rules
20
+ end
21
+ end
22
+ end
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.8.4".freeze
3
+ VERSION = "1.9.0".freeze
4
4
  end
5
5
  end
data/lib/utils/xml.rb CHANGED
@@ -62,6 +62,38 @@ module Metanorma
62
62
  end
63
63
  end
64
64
 
65
+ def noko(_script = "Latn", &block)
66
+ fragment = ::Nokogiri::XML.parse(NOKOHEAD).fragment("")
67
+ ::Nokogiri::XML::Builder.with fragment, &block
68
+ ret = fragment
69
+ .to_xml(encoding: "UTF-8", indent: 0,
70
+ save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
71
+ .lines.map do |l|
72
+ l.rstrip.gsub("&#150;", "\u0096").gsub("&#151;", "\u0097")
73
+ .gsub("&#x96;", "\u0096").gsub("&#x97;", "\u0097")
74
+ end
75
+ line_sanitise(ret)
76
+ end
77
+
78
+ # 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
81
+ def line_sanitise(ret)
82
+ ret.size == 1 and return ret
83
+ (0...ret.size).each do |i|
84
+ last = firstchar_xml(ret[i].reverse)
85
+ nextfirst = firstchar_xml(ret[i + 1])
86
+ /#{CJK}/o.match?(last) && /#{CJK}/o.match?(nextfirst) or
87
+ ret[i] += " "
88
+ end
89
+ ret
90
+ end
91
+
92
+ def firstchar_xml(line)
93
+ m = /^(<[^>]+>)*(.)/.match(line) or return ""
94
+ m[2]
95
+ end
96
+
65
97
  def noko_html(&block)
66
98
  doc = ::Nokogiri::XML.parse(NOKOHEAD)
67
99
  fragment = doc.fragment("")
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.8.4
4
+ version: 1.9.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-19 00:00:00.000000000 Z
11
+ date: 2024-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -292,6 +292,7 @@ files:
292
292
  - LICENSE
293
293
  - README.adoc
294
294
  - lib/metanorma-utils.rb
295
+ - lib/sterile/sterile.rb
295
296
  - lib/utils/hash_transform_keys.rb
296
297
  - lib/utils/image.rb
297
298
  - lib/utils/linestatus.rb