orthotypo 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -14
- data/README.md +15 -0
- data/lib/orthotypo/composer.rb +31 -13
- data/lib/orthotypo/version.rb +1 -1
- data/spec/composer/fr_spec.rb +4 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d98147f241b463ded341c2d422bc85402af278c1dba5c8120fe25de1335addb
|
4
|
+
data.tar.gz: aada22cc0374ebd5fdeea55d1d8a0b4ce84734e965f303dec5e34be9edfe82ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8a9e8e9d6ecd50bd27eb6309836508d23ed182437487dbf7f1d0130de29705aa2ef81fe7ae516dc976352a8f70d3c05146df1d74432fee615b1d47443118306
|
7
|
+
data.tar.gz: bf718bc6f49c667e203b529fad9a565c8f936ff74bd9cd54b56f60f32bd50c72e39f3a838beee66a315a53c6c1dcb13ff93266111ff1f569bbaaa69025923a38
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
orthotypo (1.0.
|
4
|
+
orthotypo (1.0.1)
|
5
5
|
htmlentities
|
6
6
|
nokogiri
|
7
7
|
|
@@ -9,24 +9,23 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
|
-
base64 (0.1.1)
|
13
12
|
byebug (11.1.3)
|
14
13
|
diff-lcs (1.5.0)
|
15
14
|
htmlentities (4.3.4)
|
16
|
-
json (2.
|
15
|
+
json (2.7.1)
|
17
16
|
language_server-protocol (3.17.0.3)
|
18
|
-
nokogiri (1.
|
17
|
+
nokogiri (1.16.0-arm64-darwin)
|
19
18
|
racc (~> 1.4)
|
20
|
-
nokogiri (1.
|
19
|
+
nokogiri (1.16.0-x86_64-darwin)
|
21
20
|
racc (~> 1.4)
|
22
|
-
parallel (1.
|
23
|
-
parser (3.
|
21
|
+
parallel (1.24.0)
|
22
|
+
parser (3.3.0.2)
|
24
23
|
ast (~> 2.4.1)
|
25
24
|
racc
|
26
|
-
racc (1.7.
|
25
|
+
racc (1.7.3)
|
27
26
|
rainbow (3.1.1)
|
28
|
-
rake (13.0
|
29
|
-
regexp_parser (2.
|
27
|
+
rake (13.1.0)
|
28
|
+
regexp_parser (2.9.0)
|
30
29
|
rexml (3.2.6)
|
31
30
|
rspec (3.12.0)
|
32
31
|
rspec-core (~> 3.12.0)
|
@@ -44,8 +43,7 @@ GEM
|
|
44
43
|
rspec (>= 3)
|
45
44
|
terminal-notifier (>= 1.4)
|
46
45
|
rspec-support (3.12.1)
|
47
|
-
rubocop (1.
|
48
|
-
base64 (~> 0.1.1)
|
46
|
+
rubocop (1.59.0)
|
49
47
|
json (~> 2.3)
|
50
48
|
language_server-protocol (>= 3.17.0)
|
51
49
|
parallel (~> 1.10)
|
@@ -53,10 +51,10 @@ GEM
|
|
53
51
|
rainbow (>= 2.2.2, < 4.0)
|
54
52
|
regexp_parser (>= 1.8, < 3.0)
|
55
53
|
rexml (>= 3.2.5, < 4.0)
|
56
|
-
rubocop-ast (>= 1.
|
54
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
57
55
|
ruby-progressbar (~> 1.7)
|
58
56
|
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
-
rubocop-ast (1.
|
57
|
+
rubocop-ast (1.30.0)
|
60
58
|
parser (>= 3.2.1.0)
|
61
59
|
ruby-progressbar (1.13.0)
|
62
60
|
terminal-notifier (2.0.0)
|
data/README.md
CHANGED
@@ -34,6 +34,21 @@ Ne pas endommager l'HTML et les HTML entities ( )
|
|
34
34
|
S'adapter aux locales (détecter I18n)
|
35
35
|
Permettre les configs
|
36
36
|
|
37
|
+
## Tests
|
38
|
+
|
39
|
+
```
|
40
|
+
rake
|
41
|
+
```
|
42
|
+
|
43
|
+
```
|
44
|
+
bundle exec rspec
|
45
|
+
```
|
46
|
+
|
47
|
+
Pour jouer un seul test :
|
48
|
+
```
|
49
|
+
bundle exec rspec ./spec/composer/fr_spec.rb:56
|
50
|
+
```
|
51
|
+
|
37
52
|
## Sources
|
38
53
|
|
39
54
|
- https://fr.wikipedia.org/wiki/Code_typographique
|
data/lib/orthotypo/composer.rb
CHANGED
@@ -75,13 +75,11 @@ module Orthotypo
|
|
75
75
|
|
76
76
|
def prepare_ortho
|
77
77
|
@ortho = string.dup
|
78
|
-
# @ortho = html_entities.decode(@ortho) if contains_html_entities?
|
79
78
|
@nokogiri = Nokogiri::HTML.fragment @ortho
|
80
79
|
end
|
81
80
|
|
82
81
|
def clean_ortho
|
83
82
|
@ortho = @nokogiri.to_s
|
84
|
-
# @ortho = html_entities.encode(@ortho) if contains_html_entities?
|
85
83
|
end
|
86
84
|
|
87
85
|
def parse
|
@@ -98,7 +96,7 @@ module Orthotypo
|
|
98
96
|
parse_pairs_with_no_space_around
|
99
97
|
# Numbers
|
100
98
|
parse_chars_in_numbers
|
101
|
-
#
|
99
|
+
#
|
102
100
|
clean_ortho
|
103
101
|
restore_precious_things
|
104
102
|
end
|
@@ -106,20 +104,40 @@ module Orthotypo
|
|
106
104
|
def preserve_precious_things
|
107
105
|
@precious_things = []
|
108
106
|
@nokogiri.traverse do |node|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
107
|
+
if node.text?
|
108
|
+
has_leading_space = node.content.start_with? SPACE
|
109
|
+
has_trailing_space = node.content.end_with? SPACE
|
110
|
+
node.content = node.content.split(SPACE).map { |fragment|
|
111
|
+
store_if_precious(fragment)
|
112
|
+
}.join(SPACE)
|
113
|
+
node.content = SPACE + node.content if has_leading_space
|
114
|
+
node.content = node.content + SPACE if has_trailing_space
|
115
|
+
elsif node.element?
|
116
|
+
if node.name == 'a'
|
117
|
+
node.attributes.each do |key, attribute|
|
118
|
+
if attribute.name == 'href'
|
119
|
+
attribute.value = store_precious_thing(attribute.value)
|
120
|
+
end
|
121
|
+
end
|
117
122
|
end
|
118
|
-
|
119
|
-
node.content = new_content
|
123
|
+
end
|
120
124
|
end
|
121
125
|
end
|
122
126
|
|
127
|
+
def store_if_precious(string)
|
128
|
+
Analyzer::precious?(string) ? store_precious_thing(string)
|
129
|
+
: string
|
130
|
+
end
|
131
|
+
|
132
|
+
def store_precious_thing(string)
|
133
|
+
# Create token identifier
|
134
|
+
token = "#{PRECIOUS_TOKEN}#{@precious_things.length}"
|
135
|
+
# Store value
|
136
|
+
@precious_things << string
|
137
|
+
# Return identifier
|
138
|
+
token
|
139
|
+
end
|
140
|
+
|
123
141
|
def restore_precious_things
|
124
142
|
@precious_things.each_with_index do |value, index|
|
125
143
|
@ortho.gsub! "#{PRECIOUS_TOKEN}#{index}", value
|
data/lib/orthotypo/version.rb
CHANGED
data/spec/composer/fr_spec.rb
CHANGED
@@ -53,6 +53,10 @@ describe Orthotypo::Composer::Fr do
|
|
53
53
|
expect("10 octobre 2023 16:00".ortho).to(eq("10 octobre 2023 16:00"))
|
54
54
|
end
|
55
55
|
|
56
|
+
it 'does well with HTML' do
|
57
|
+
expect("<p><a href=\"https://www.linkedin.com/in/marie-dewet-1397a094/\">Marie Dewet</a>, Co-fondatrice de <a href=\"https://www.linkedin.com/company/maisoncleo/\">MaisonCléo</a> nous apporte ses lumières.</p>".ortho).to(eq("<p><a href=\"https://www.linkedin.com/in/marie-dewet-1397a094/\">Marie Dewet</a>, Co-fondatrice de <a href=\"https://www.linkedin.com/company/maisoncleo/\">MaisonCléo</a> nous apporte ses lumières.</p>"))
|
58
|
+
end
|
59
|
+
|
56
60
|
# https://www.scribbr.fr/elements-linguistiques/les-espaces/
|
57
61
|
it 'tests de Justine Debret' do
|
58
62
|
expect("Elle a vu son cousin,sa tante et son oncle.Ils allaient tous très bien.".ortho).to(eq("Elle a vu son cousin, sa tante et son oncle. Ils allaient tous très bien."))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthotypo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.4.
|
143
|
+
rubygems_version: 3.4.10
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Pour un texte correctement typographié
|