metanorma-utils 1.8.2 → 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: 4137257679b627f458d91b4931f6de9d7956af0cb50661f17c6c7a035cb98fc8
4
- data.tar.gz: 631a4d0c9554f357c0cb815fb0f13b0353d08451d81fb05cb26c3c99cc6f76ff
3
+ metadata.gz: acea881df59c64c2137792a3fc9bbb5a36d09dd43fc5fa6d0e3b066b3bbb60da
4
+ data.tar.gz: 00fc04e75a5eec309ed1a1d62633e7c9358e93adbf0558f12bad11fa069d4441
5
5
  SHA512:
6
- metadata.gz: 3d5fd0bcd6479a83094f17c748e67815cf044ba183c61c9344dfb2d54fdd49c6cda283aff42bfc25f0ad9bc8df7e87dc18c96ba67f9e2c3dc1ab1fa924b45de7
7
- data.tar.gz: 3af52dc1dcec7a36d0c9e4abd6605f0a99af743e8cf1e67466a6cf5f9d2df03b7c01775293843c3df180098285c767b8348080df5e473ef5c8fb40f4b0057228
6
+ metadata.gz: 2ba485eb93b52444caa930e05dc185f8506fc1d68c70483f43593e560e63ab418aeea60375e579363b120a7864046daefe4cd6ded9769491990748a88570cf83
7
+ data.tar.gz: c16aecbe71a3acdede53591130d310f9745fc3b8d59a7624250d36ab93468a0f16ecc05b6251c10d6dac34bab792fd15fb0344a2cd30e606f4166b4d5ed045af
@@ -61,8 +61,7 @@ module Metanorma
61
61
  v1.merge(v2, &merger)
62
62
  elsif ::Array === v1 && ::Array === v2
63
63
  v1 | v2
64
- elsif [:undefined, nil,
65
- :nil].include?(v2)
64
+ elsif [:undefined].include?(v2)
66
65
  v1
67
66
  else
68
67
  v2
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.2".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.2
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-17 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