trek 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/lib/generators/trek/templates/migrations/taggings.rb.erb +1 -1
- data/lib/trek/typography_formatter.rb +37 -5
- data/lib/trek/version.rb +1 -1
- data/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b09da98ecaf56b2d61965f064a51258bc84dced5267977541a810f33416ee2f
|
|
4
|
+
data.tar.gz: ad5b3dfc7aaaeef7c8d996fd7ba89ee3f5057c5b93d9c40bcba859c37035b2d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee62982045c3a349abfe75033fe60731cffb498408af1c6375afde95ef4477a7476f8781c4a206f72d4e04565e886165b652c9da488d0f8c3eb97c0a2c9b256b
|
|
7
|
+
data.tar.gz: dcb6b91baad0d783cefcf01c3afb15b54292d105844c291738e2a5972d96905c3c23e6d83435b35a78d0857eb7c12088d01ed21de3a595e8677002c26e214a29
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
trek (0.1.
|
|
4
|
+
trek (0.1.15)
|
|
5
5
|
action_policy (~> 0.6)
|
|
6
6
|
actioncable
|
|
7
7
|
acts_as_list (~> 1.1)
|
|
@@ -295,9 +295,9 @@ GEM
|
|
|
295
295
|
net-smtp (0.5.1)
|
|
296
296
|
net-protocol
|
|
297
297
|
nio4r (2.7.5)
|
|
298
|
-
nokogiri (1.19.
|
|
298
|
+
nokogiri (1.19.1-arm64-darwin)
|
|
299
299
|
racc (~> 1.4)
|
|
300
|
-
nokogiri (1.19.
|
|
300
|
+
nokogiri (1.19.1-x86_64-darwin)
|
|
301
301
|
racc (~> 1.4)
|
|
302
302
|
parallel (1.27.0)
|
|
303
303
|
parser (3.3.10.0)
|
|
@@ -313,7 +313,7 @@ GEM
|
|
|
313
313
|
prettyprint
|
|
314
314
|
prettyprint (0.2.0)
|
|
315
315
|
prism (1.7.0)
|
|
316
|
-
prosemirror_to_html (0.
|
|
316
|
+
prosemirror_to_html (0.3.0)
|
|
317
317
|
nokogiri
|
|
318
318
|
psych (5.3.1)
|
|
319
319
|
date
|
|
@@ -2,28 +2,60 @@ module Trek
|
|
|
2
2
|
# `TypographyFormatter` formats strings to enforce typography rules.
|
|
3
3
|
# For now, only French typography rules about non-breaking spaces
|
|
4
4
|
# and ellipsis are implemented.
|
|
5
|
+
#
|
|
6
|
+
# Supports both plain strings and ProseMirror JSONB hashes. When given
|
|
7
|
+
# a Hash, it walks the node tree and formats only `text` node values
|
|
8
|
+
# in place, leaving the structure intact.
|
|
5
9
|
class TypographyFormatter
|
|
6
10
|
NBSP = [160].pack("U*").freeze
|
|
7
11
|
NBSP_BEFORE_CHARS = %w[: ; % € \$ °C °F » ! \? –].freeze
|
|
8
12
|
NBSP_AFTER_CHARS = %w[«].freeze
|
|
9
13
|
NBSP_BEFORE_UNITS = %w[g h ha kg km Ko ko kW L l m min ml Mo mo s].freeze
|
|
10
14
|
|
|
11
|
-
def initialize(
|
|
12
|
-
@source =
|
|
13
|
-
@
|
|
15
|
+
def initialize(input)
|
|
16
|
+
@source = input
|
|
17
|
+
@prosemirror = input.is_a?(Hash)
|
|
18
|
+
@output = @prosemirror ? deep_dup_hash(input) : input.dup
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
def formatted
|
|
17
22
|
return @output if @output.nil?
|
|
18
23
|
|
|
24
|
+
if @prosemirror
|
|
25
|
+
format_prosemirror_node(@output)
|
|
26
|
+
else
|
|
27
|
+
format_string!
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
@output
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def format_string!
|
|
19
36
|
remove_double_spaces
|
|
20
37
|
add_nbsp
|
|
21
38
|
replace_ellipsis
|
|
39
|
+
end
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
def format_prosemirror_node(node)
|
|
42
|
+
return unless node.is_a?(Hash)
|
|
43
|
+
|
|
44
|
+
if node["type"] == "text" && node["text"].is_a?(String)
|
|
45
|
+
formatter = self.class.new(node["text"])
|
|
46
|
+
node["text"] = formatter.formatted
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Array(node["content"]).each { |child| format_prosemirror_node(child) }
|
|
24
50
|
end
|
|
25
51
|
|
|
26
|
-
|
|
52
|
+
def deep_dup_hash(obj)
|
|
53
|
+
case obj
|
|
54
|
+
when Hash then obj.transform_values { |v| deep_dup_hash(v) }
|
|
55
|
+
when Array then obj.map { |v| deep_dup_hash(v) }
|
|
56
|
+
else obj.dup rescue obj
|
|
57
|
+
end
|
|
58
|
+
end
|
|
27
59
|
|
|
28
60
|
def remove_double_spaces
|
|
29
61
|
@output.gsub!(/(\p{Zs}{2,})/, " ")
|
data/lib/trek/version.rb
CHANGED
data/package.json
CHANGED