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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd24cbdb2c5adaa4f6ecf91acf144025549b7599aeb0f944e3f1987331448450
4
- data.tar.gz: 6d9a7bb478c4cc0b76722128a1065fc99666f7d1f284cc82cb6f26acfe89bf70
3
+ metadata.gz: 7d98147f241b463ded341c2d422bc85402af278c1dba5c8120fe25de1335addb
4
+ data.tar.gz: aada22cc0374ebd5fdeea55d1d8a0b4ce84734e965f303dec5e34be9edfe82ac
5
5
  SHA512:
6
- metadata.gz: e51b243378c8d97df6fd3bfa7f59a7aeb7f516d3f54d82cce4eb0ae8d3c7b6a5893211c857c72f8c249a73e0333f3d187ddf4d6145a45ab6de5039633aeaf457
7
- data.tar.gz: dc77c1043a6210122c48a8d5849d63df04247d3d957707469d9e3029ed0cf1a9bec745cd12115bb4563254abc6e227c74e13f02285fc0cada9a0d75ab0be2ad6
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.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.6.3)
15
+ json (2.7.1)
17
16
  language_server-protocol (3.17.0.3)
18
- nokogiri (1.15.4-arm64-darwin)
17
+ nokogiri (1.16.0-arm64-darwin)
19
18
  racc (~> 1.4)
20
- nokogiri (1.15.4-x86_64-darwin)
19
+ nokogiri (1.16.0-x86_64-darwin)
21
20
  racc (~> 1.4)
22
- parallel (1.23.0)
23
- parser (3.2.2.4)
21
+ parallel (1.24.0)
22
+ parser (3.3.0.2)
24
23
  ast (~> 2.4.1)
25
24
  racc
26
- racc (1.7.1)
25
+ racc (1.7.3)
27
26
  rainbow (3.1.1)
28
- rake (13.0.6)
29
- regexp_parser (2.8.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.57.0)
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.28.1, < 2.0)
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.29.0)
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 (&nbsp;)
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
@@ -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
- next unless node.text?
110
- new_content = node.content.split(SPACE).map { |fragment|
111
- if Analyzer::precious?(fragment)
112
- token = "#{PRECIOUS_TOKEN}#{@precious_things.length}"
113
- @precious_things << fragment
114
- token
115
- else
116
- fragment
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
- }.join(SPACE)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthotypo
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
@@ -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.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: 2023-10-23 00:00:00.000000000 Z
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.6
143
+ rubygems_version: 3.4.10
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Pour un texte correctement typographié