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 +4 -4
- data/lib/sterile/sterile.rb +22 -0
- data/lib/utils/version.rb +1 -1
- data/lib/utils/xml.rb +32 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 717014b944b65d1e4f5b7c7ed0c71b3ac3314a3fb9ac740ff0027e9b5088cea8
|
4
|
+
data.tar.gz: c5bc40281e230a272deaf0469d4b9b6dd85e4f6b124de1e64d4c5c16347b2e8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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("–", "\u0096").gsub("—", "\u0097")
|
73
|
+
.gsub("–", "\u0096").gsub("—", "\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.
|
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-
|
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
|