metanorma-utils 1.8.3 → 1.8.4

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: c4941f1b2ce404a56da0e5c3ae8d1a3e9867cf938a6cb5e0cab243a9ebbe8b14
4
- data.tar.gz: 1ba1f75ac3da74bb847795aed139e9e1c011f107b8d0e44c59248cd4cdfe37ff
3
+ metadata.gz: acea881df59c64c2137792a3fc9bbb5a36d09dd43fc5fa6d0e3b066b3bbb60da
4
+ data.tar.gz: 00fc04e75a5eec309ed1a1d62633e7c9358e93adbf0558f12bad11fa069d4441
5
5
  SHA512:
6
- metadata.gz: a1168eb36b3d478709bd0e542ded060e8721b4f89f70013fe115145b184eaa638f9fcccb3278d5feb7155db809b23d478cb20a1d4894d89c80bf774ab6fccd20
7
- data.tar.gz: 4a1d3b8a28f075b78e6b162af9c9c391d71d2372852481d48499597e6851c9f1eb829a1b011b2a0e56a94f0b6c173869714cbae7867b79891e498158dbc47497
6
+ metadata.gz: 2ba485eb93b52444caa930e05dc185f8506fc1d68c70483f43593e560e63ab418aeea60375e579363b120a7864046daefe4cd6ded9769491990748a88570cf83
7
+ data.tar.gz: c16aecbe71a3acdede53591130d310f9745fc3b8d59a7624250d36ab93468a0f16ecc05b6251c10d6dac34bab792fd15fb0344a2cd30e606f4166b4d5ed045af
data/lib/utils/main.rb CHANGED
@@ -4,6 +4,7 @@ require "sterile"
4
4
  require "htmlentities"
5
5
  require "nokogiri"
6
6
  require "csv"
7
+ require_relative "../sterile/sterile"
7
8
 
8
9
  module Metanorma
9
10
  module Utils
@@ -34,21 +35,26 @@ module Metanorma
34
35
  docfile.nil? ? "./" : "#{Pathname.new(docfile).parent}/"
35
36
  end
36
37
 
37
- # TODO needs internationalisation
38
+ CJK = "\\p{Han}|\\p{Bopomofo}|\\p{Hangul}|\\p{Hiragana}|\\p{Katakana}"
39
+ .freeze
40
+
41
+ # TODO needs internationalisation of quote
38
42
  def smartformat(text)
39
- HTMLEntities.new.encode(
40
- HTMLEntities.new.decode(
41
- text.gsub(/ --? /, " — ")
42
- .gsub("--", "—"),
43
- )
44
- .smart_format, :basic
43
+ ret = HTMLEntities.new.decode(
44
+ text.gsub(/ --? /, " — ")
45
+ .gsub("--", "—"),
45
46
  )
47
+ ret = ret.gsub(%r{(#{CJK})(["'])}o, "\\1\u200a\\2")
48
+ .gsub(%r{(["'])(#{CJK})}o, "\\1\u200a\\2")
49
+ ret = ret.smart_format
50
+ ret = ret.gsub(%r{(#{CJK})\u200a}o, "\\1")
51
+ .gsub(%r{\u200a(#{CJK})}o, "\\1")
52
+ HTMLEntities.new.encode(ret, :basic)
46
53
  end
47
54
 
48
55
  def endash_date(elem)
49
56
  elem.traverse do |n|
50
- next unless n.text?
51
-
57
+ n.text? or next
52
58
  n.replace(n.text.gsub(/\s+--?\s+/, "–").gsub("--", "–"))
53
59
  end
54
60
  end
@@ -133,7 +139,8 @@ module Metanorma
133
139
  # if punct fails, try break on camel case, with soft hyphen
134
140
  # break regardless every LONGSTRING_THRESHOLD * LONGSTR_NOPUNCT,
135
141
  # with soft hyphen
136
- def break_up_long_str(text, threshold = LONGSTR_THRESHOLD, nopunct = LONGSTR_NOPUNCT)
142
+ def break_up_long_str(text, threshold = LONGSTR_THRESHOLD,
143
+ nopunct = LONGSTR_NOPUNCT)
137
144
  /^\s*$/.match?(text) and return text
138
145
  text.split(/(?=(?:\s|-))/).map do |w|
139
146
  if /^\s*$/.match(text) || (w.size < threshold) then w
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.8.3".freeze
3
+ VERSION = "1.8.4".freeze
4
4
  end
5
5
  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.8.3
4
+ version: 1.8.4
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-18 00:00:00.000000000 Z
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor