orthotypo 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/orthotypo/analyzer.rb +18 -0
- data/lib/orthotypo/composer/en.rb +18 -0
- data/lib/orthotypo/composer/en_gb.rb +5 -0
- data/lib/orthotypo/composer/fr.rb +57 -0
- data/lib/orthotypo/composer/fr_ch.rb +4 -0
- data/lib/orthotypo/composer/fr_fr.rb +4 -0
- data/lib/orthotypo/composer.rb +182 -0
- data/lib/orthotypo/core_ext.rb +5 -0
- data/lib/orthotypo/localizer.rb +32 -0
- data/lib/orthotypo/version.rb +5 -0
- data/lib/orthotypo.rb +19 -0
- data/orthotypo.gemspec +29 -0
- data/sig/orthotypo.rbs +4 -0
- data/spec/analyzer_spec.rb +8 -0
- data/spec/composer/en_spec.rb +17 -0
- data/spec/composer/fr_spec.rb +62 -0
- data/spec/localizer_spec.rb +13 -0
- data/spec/orthotypo_spec.rb +21 -0
- data/spec/spec_helper.rb +2 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b41b05766be4f11e6494a7e89823a6ab730910aec4a679d22b764ae96fb05f10
|
4
|
+
data.tar.gz: 0c2a072f5c3ebd8583b70c7ee4bf0eafe064c827d4e0af250728bcf5762dc5ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20ff73ede6bf05d4b2b8842604b09267f36cf2d44fc17c6e4a467e9e703934a20f18616368cc5af88529122166130c8b868612af6caab95ff6f685236b862443
|
7
|
+
data.tar.gz: 55f9a2023f185176d52de197847f92ee61ea0e8ba20d70c920fec7e31b4d86dbae0ab87594adcd7c406fcdbbc2ef189fa8a113bcfeab9f60786c31dd77771f1e
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at contact@arnaudlevy.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
orthotypo (0.6.0)
|
5
|
+
htmlentities
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
base64 (0.1.1)
|
13
|
+
byebug (11.1.3)
|
14
|
+
diff-lcs (1.5.0)
|
15
|
+
htmlentities (4.3.4)
|
16
|
+
json (2.6.3)
|
17
|
+
language_server-protocol (3.17.0.3)
|
18
|
+
nokogiri (1.15.4-arm64-darwin)
|
19
|
+
racc (~> 1.4)
|
20
|
+
nokogiri (1.15.4-x86_64-darwin)
|
21
|
+
racc (~> 1.4)
|
22
|
+
parallel (1.23.0)
|
23
|
+
parser (3.2.2.4)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
racc
|
26
|
+
racc (1.7.1)
|
27
|
+
rainbow (3.1.1)
|
28
|
+
rake (13.0.6)
|
29
|
+
regexp_parser (2.8.2)
|
30
|
+
rexml (3.2.6)
|
31
|
+
rspec (3.12.0)
|
32
|
+
rspec-core (~> 3.12.0)
|
33
|
+
rspec-expectations (~> 3.12.0)
|
34
|
+
rspec-mocks (~> 3.12.0)
|
35
|
+
rspec-core (3.12.2)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-expectations (3.12.3)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-mocks (3.12.6)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-nc (0.3.0)
|
44
|
+
rspec (>= 3)
|
45
|
+
terminal-notifier (>= 1.4)
|
46
|
+
rspec-support (3.12.1)
|
47
|
+
rubocop (1.57.0)
|
48
|
+
base64 (~> 0.1.1)
|
49
|
+
json (~> 2.3)
|
50
|
+
language_server-protocol (>= 3.17.0)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.2.2.4)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.8, < 3.0)
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.29.0)
|
60
|
+
parser (>= 3.2.1.0)
|
61
|
+
ruby-progressbar (1.13.0)
|
62
|
+
terminal-notifier (2.0.0)
|
63
|
+
unicode-display_width (2.5.0)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
arm64-darwin-22
|
67
|
+
x86_64-darwin-22
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
byebug
|
71
|
+
orthotypo!
|
72
|
+
rake (~> 13.0)
|
73
|
+
rspec
|
74
|
+
rspec-nc
|
75
|
+
rubocop (~> 1.21)
|
76
|
+
|
77
|
+
BUNDLED WITH
|
78
|
+
2.4.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 noesya
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Orthotypo
|
2
|
+
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/16eb1f100538684deee0/maintainability)](https://codeclimate.com/github/noesya/orthotypo/maintainability)
|
4
|
+
|
5
|
+
Il y a un corpus riche de règles typographiques, dépendant des langues.
|
6
|
+
Cette gem vise à intégrer ces règles et à automatiser leurs mises en application pour le web, quand cela est possible.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install the gem and add to the application's Gemfile by executing:
|
11
|
+
|
12
|
+
$ bundle add orthotypo
|
13
|
+
|
14
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
15
|
+
|
16
|
+
$ gem install orthotypo
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Ajout d'espace fine insécable avant les signes doubles en français.
|
21
|
+
|
22
|
+
```
|
23
|
+
"Un texte avec un signe double: mais il manque l'espace.".ortho
|
24
|
+
> Un texte avec un signe double : mais il manque l'espace.
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
## Roadmap
|
29
|
+
|
30
|
+
### v1
|
31
|
+
1. S'adapter aux locales (détecter I18n)
|
32
|
+
2. Ne pas endommager l'HTML et les HTML entities ( )
|
33
|
+
|
34
|
+
### v2
|
35
|
+
Permettre les configs
|
36
|
+
|
37
|
+
## Sources
|
38
|
+
|
39
|
+
- https://fr.wikipedia.org/wiki/Code_typographique
|
40
|
+
- http://www.orthotypographie.fr/
|
41
|
+
- https://www.scribbr.fr/elements-linguistiques/les-espaces/
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/noesya/orthotypo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/orthotypo/blob/main/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
## Code of Conduct
|
56
|
+
|
57
|
+
Everyone interacting in the Orthotypo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/orthotypo/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "orthotypo"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Orthotypo
|
2
|
+
class Analyzer
|
3
|
+
|
4
|
+
def self.url?(string)
|
5
|
+
(string =~ /\A#{URI::DEFAULT_PARSER.regexp[:ABS_URI]}\z/) &&
|
6
|
+
(string =~ /\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/ix) ? true : false
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.email?(string)
|
10
|
+
string =~ /\A#{URI::MailTo::EMAIL_REGEXP}\z/ ? true : false
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.precious?(string)
|
14
|
+
email?(string) || url?(string)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Orthotypo
|
2
|
+
class Composer::Fr < Composer
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def chars_with_space_before
|
7
|
+
[
|
8
|
+
'%'
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
def chars_with_space_after
|
13
|
+
[
|
14
|
+
',',
|
15
|
+
'.',
|
16
|
+
'...',
|
17
|
+
'…'
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
def chars_with_space_around
|
22
|
+
[
|
23
|
+
';',
|
24
|
+
':',
|
25
|
+
'!',
|
26
|
+
'?'
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
def chars_with_no_space_around
|
31
|
+
[
|
32
|
+
"'",
|
33
|
+
'’',
|
34
|
+
'ʼ'
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
def pairs_with_space_around
|
39
|
+
[
|
40
|
+
'«»'
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def pairs_with_no_space_around
|
45
|
+
[
|
46
|
+
'“”',
|
47
|
+
'‘’',
|
48
|
+
'‹›',
|
49
|
+
'""',
|
50
|
+
"''",
|
51
|
+
"()",
|
52
|
+
"{}",
|
53
|
+
"[]"
|
54
|
+
]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
module Orthotypo
|
2
|
+
class Composer
|
3
|
+
attr_reader :string, :ortho
|
4
|
+
|
5
|
+
SPACE = ' '.freeze
|
6
|
+
NBSP = ' '.freeze
|
7
|
+
NNBSP = ' '.freeze
|
8
|
+
PRECIOUS_TOKEN = 'orthotypopreciousthing'
|
9
|
+
|
10
|
+
def initialize(string, html: nil)
|
11
|
+
@string = string
|
12
|
+
@html = html
|
13
|
+
parse
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def chars_with_space_before
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
|
22
|
+
def chars_with_space_after
|
23
|
+
[
|
24
|
+
',',
|
25
|
+
'.'
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def chars_with_space_around
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
|
33
|
+
def chars_with_no_space_around
|
34
|
+
[]
|
35
|
+
end
|
36
|
+
|
37
|
+
def pairs_with_space_around
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
|
41
|
+
def pairs_with_no_space_around
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_html?
|
46
|
+
# TODO contains tags?
|
47
|
+
@html || contains_html_entities?
|
48
|
+
end
|
49
|
+
|
50
|
+
def contains_html_entities?
|
51
|
+
@contains_html_entities ||= html_entities.decode(string) != string
|
52
|
+
end
|
53
|
+
|
54
|
+
def prepare_ortho
|
55
|
+
@ortho = string.dup
|
56
|
+
# @ortho = html_entities.decode(@ortho) if contains_html_entities?
|
57
|
+
@nokogiri = Nokogiri::HTML.fragment @ortho
|
58
|
+
end
|
59
|
+
|
60
|
+
def clean_ortho
|
61
|
+
@ortho = @nokogiri.to_s
|
62
|
+
# @ortho = html_entities.encode(@ortho) if contains_html_entities?
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse
|
66
|
+
prepare_ortho
|
67
|
+
preserve_precious_things
|
68
|
+
# Chars
|
69
|
+
parse_chars_with_space_before
|
70
|
+
parse_chars_with_space_after
|
71
|
+
parse_chars_with_space_around
|
72
|
+
parse_chars_with_no_space_around
|
73
|
+
# Pairs
|
74
|
+
parse_pairs_with_space_around
|
75
|
+
parse_pairs_with_no_space_around
|
76
|
+
# Numbers
|
77
|
+
parse_numbers
|
78
|
+
#
|
79
|
+
clean_ortho
|
80
|
+
restore_precious_things
|
81
|
+
end
|
82
|
+
|
83
|
+
def preserve_precious_things
|
84
|
+
@precious_things = []
|
85
|
+
@nokogiri.traverse do |node|
|
86
|
+
next unless node.text?
|
87
|
+
new_content = node.content.split(SPACE).map { |fragment|
|
88
|
+
if Analyzer::precious?(fragment)
|
89
|
+
token = "#{PRECIOUS_TOKEN}#{@precious_things.length}"
|
90
|
+
@precious_things << fragment
|
91
|
+
token
|
92
|
+
else
|
93
|
+
fragment
|
94
|
+
end
|
95
|
+
}.join(SPACE)
|
96
|
+
node.content = new_content
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def restore_precious_things
|
101
|
+
@precious_things.each_with_index do |value, index|
|
102
|
+
@ortho.gsub! "#{PRECIOUS_TOKEN}#{index}", value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def parse_chars_with_space_before
|
107
|
+
chars_with_space_before.each do |char|
|
108
|
+
# Espace normal avant -> espace fine insécable avant
|
109
|
+
fix(SPACE + '%', NNBSP + '%')
|
110
|
+
# Pas d'espace avant -> espace fine insécable avant
|
111
|
+
fix(/([[:alnum:]])%/, "\\1" + NNBSP + '%')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def parse_chars_with_space_after
|
116
|
+
chars_with_space_after.each do |char|
|
117
|
+
# Espace avant -> pas d'espace avant
|
118
|
+
fix(SPACE + char, char)
|
119
|
+
# Pas d'espace après -> espace après
|
120
|
+
fix(/[#{char}]([[:alnum:]])/, char + SPACE + "\\1")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def parse_chars_with_space_around
|
125
|
+
chars_with_space_around.each do |char|
|
126
|
+
# Espace normal avant -> espace fine insécable avant
|
127
|
+
fix(SPACE + char, NNBSP + char)
|
128
|
+
# Pas d'espace avant -> espace fine insécable avant
|
129
|
+
fix(/([[:alnum:]])[#{char}]/, "\\1" + NNBSP + char)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def parse_chars_with_no_space_around
|
134
|
+
chars_with_no_space_around.each do |char|
|
135
|
+
# Espace avant -> pas d'espace avant
|
136
|
+
fix(SPACE + char, char)
|
137
|
+
# Espace après -> pas d'espace après
|
138
|
+
fix(char + SPACE, char)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def parse_pairs_with_space_around
|
143
|
+
pairs_with_space_around.each do |marks|
|
144
|
+
opening = marks.chars.first
|
145
|
+
closing = marks.chars.last
|
146
|
+
# Espace normal -> espace fine insécable
|
147
|
+
fix(opening + SPACE, opening + NNBSP)
|
148
|
+
fix(SPACE + closing, NNBSP + closing)
|
149
|
+
# Pas d'espace -> espace fine insécable
|
150
|
+
fix(/[#{opening}]([^[:space:]])/, opening + NNBSP + "\\1")
|
151
|
+
fix(/([^[:space:]])[#{closing}]/, "\\1" + NNBSP + closing)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def parse_pairs_with_no_space_around
|
156
|
+
pairs_with_no_space_around.each do |marks|
|
157
|
+
opening = marks.chars.first
|
158
|
+
closing = marks.chars.last
|
159
|
+
# Espace -> pas d'espace
|
160
|
+
fix(opening + SPACE, opening)
|
161
|
+
fix(SPACE + closing, closing)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def parse_numbers
|
166
|
+
['.', ','].each do |char|
|
167
|
+
fix(/([[:digit:]])[#{char}][[:space:]]([[:digit:]])/, "\\1" + char + "\\2")
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def html_entities
|
172
|
+
@html_entities ||= HTMLEntities.new(:expanded)
|
173
|
+
end
|
174
|
+
|
175
|
+
def fix(bad, good)
|
176
|
+
@nokogiri.traverse do |node|
|
177
|
+
next unless node.text?
|
178
|
+
node.content = node.content.gsub(bad, good)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Orthotypo
|
2
|
+
class Localizer
|
3
|
+
|
4
|
+
DEFAULT_LOCALE = 'fr'
|
5
|
+
|
6
|
+
def initialize(string, locale: nil, html: nil)
|
7
|
+
@string = string
|
8
|
+
@locale = locale
|
9
|
+
@html = html
|
10
|
+
end
|
11
|
+
|
12
|
+
def composer
|
13
|
+
composer_class.new @string, html: @html
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def composer_class
|
19
|
+
composer_class = composer_class_for(@locale) unless @locale.nil?
|
20
|
+
composer_class ||= composer_class_for(DEFAULT_LOCALE)
|
21
|
+
composer_class
|
22
|
+
end
|
23
|
+
|
24
|
+
def composer_class_for(locale)
|
25
|
+
formatted_locale = locale.split('-').map(&:capitalize).join
|
26
|
+
class_name = "::Orthotypo::Composer::#{formatted_locale}"
|
27
|
+
Object.module_eval(class_name, __FILE__, __LINE__)
|
28
|
+
rescue
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/orthotypo.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "htmlentities"
|
4
|
+
require "nokogiri"
|
5
|
+
require "uri"
|
6
|
+
require_relative "orthotypo/analyzer"
|
7
|
+
require_relative "orthotypo/composer"
|
8
|
+
require_relative "orthotypo/composer/fr"
|
9
|
+
require_relative "orthotypo/composer/fr_fr"
|
10
|
+
require_relative "orthotypo/composer/fr_ch"
|
11
|
+
require_relative "orthotypo/composer/en"
|
12
|
+
require_relative "orthotypo/composer/en_gb"
|
13
|
+
require_relative "orthotypo/core_ext"
|
14
|
+
require_relative "orthotypo/localizer"
|
15
|
+
require_relative "orthotypo/version"
|
16
|
+
|
17
|
+
module Orthotypo
|
18
|
+
class Error < StandardError; end
|
19
|
+
end
|
data/orthotypo.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/orthotypo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "orthotypo"
|
7
|
+
spec.version = Orthotypo::VERSION
|
8
|
+
spec.authors = ["Arnaud Levy"]
|
9
|
+
spec.email = ["arnaud.levy@noesya.coop"]
|
10
|
+
|
11
|
+
spec.summary = "Pour un texte correctement typographié"
|
12
|
+
spec.description = "Il y a un corpus riche de règles typographiques, dépendant des langues. Cette gem vise à intégrer ces règles et à automatiser leur mise en application pour le web, quand cela est possible."
|
13
|
+
spec.homepage = "https://github.com/noesya/orthotypo"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/noesya/orthotypo"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split("\n")
|
21
|
+
spec.require_paths = "lib"
|
22
|
+
|
23
|
+
spec.add_dependency "htmlentities"
|
24
|
+
spec.add_dependency "nokogiri"
|
25
|
+
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rspec-nc"
|
28
|
+
spec.add_development_dependency "byebug"
|
29
|
+
end
|
data/sig/orthotypo.rbs
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Orthotypo::Composer::En do
|
5
|
+
it 'removes spaces before double punctuation marks' do
|
6
|
+
expect("mot: suite".ortho(locale: 'en')).to eq "mot: suite"
|
7
|
+
expect("mot : suite".ortho(locale: 'en')).to eq "mot: suite"
|
8
|
+
expect("é: suite".ortho(locale: 'en')).to eq "é: suite"
|
9
|
+
expect("é : suite".ortho(locale: 'en')).to eq "é: suite"
|
10
|
+
expect("1: suite".ortho(locale: 'en')).to eq "1: suite"
|
11
|
+
expect("1 : suite".ortho(locale: 'en')).to eq "1: suite"
|
12
|
+
expect("mot; suite".ortho(locale: 'en')).to eq "mot; suite"
|
13
|
+
expect("mot ; suite".ortho(locale: 'en')).to eq "mot; suite"
|
14
|
+
expect("mot!".ortho(locale: 'en')).to eq "mot!"
|
15
|
+
expect("mot !".ortho(locale: 'en')).to eq "mot!"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Orthotypo::Composer::Fr do
|
5
|
+
it 'adds spaces before double punctuation marks' do
|
6
|
+
expect("mot: suite".ortho).to(eq("mot : suite"))
|
7
|
+
expect("é: suite".ortho).to(eq("é : suite"))
|
8
|
+
expect("1: suite".ortho).to(eq("1 : suite"))
|
9
|
+
expect("mot; suite".ortho).to(eq("mot ; suite"))
|
10
|
+
expect("mot!".ortho).to(eq("mot !"))
|
11
|
+
expect("mot !".ortho).to(eq("mot !"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'transforms regular spaces before double punctuation marks' do
|
15
|
+
expect("mot : suite".ortho).to(eq("mot : suite"))
|
16
|
+
expect("é : suite".ortho).to(eq("é : suite"))
|
17
|
+
expect("1 : suite".ortho).to(eq("1 : suite"))
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'fixes space before simple punctuation' do
|
21
|
+
expect("mot , suite".ortho).to(eq("mot, suite"))
|
22
|
+
expect("mot . suite".ortho).to(eq("mot. suite"))
|
23
|
+
expect("l 'approche".ortho).to(eq("l'approche"))
|
24
|
+
expect("l' approche".ortho).to(eq("l'approche"))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'fixes space after simple punctuation' do
|
28
|
+
expect("mot,suite".ortho).to(eq("mot, suite"))
|
29
|
+
expect("4,5".ortho).to(eq("4,5"))
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'fixes quotation marks' do
|
33
|
+
expect("«mot»".ortho).to(eq("« mot »"))
|
34
|
+
expect("« mot »".ortho).to(eq("« mot »"))
|
35
|
+
expect("“ mot ”".ortho).to(eq("“mot”"))
|
36
|
+
expect("‘ mot ’".ortho).to(eq("‘mot’"))
|
37
|
+
expect("‹ mot ›".ortho).to(eq("‹mot›"))
|
38
|
+
expect("\" mot \"".ortho).to(eq("\"mot\""))
|
39
|
+
expect("' mot '".ortho).to(eq("'mot'"))
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'fixes percent' do
|
43
|
+
expect("10%".ortho).to(eq("10 %"))
|
44
|
+
expect("10 %".ortho).to(eq("10 %"))
|
45
|
+
end
|
46
|
+
|
47
|
+
# https://www.scribbr.fr/elements-linguistiques/les-espaces/
|
48
|
+
it 'tests de Justine Debret' do
|
49
|
+
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."))
|
50
|
+
expect("Elle dit: qui voudrait bien venir voir ce film? Il répond: moi; à moins qu’il ne fasse très beau!".ortho).to(eq("Elle dit : qui voudrait bien venir voir ce film ? Il répond : moi ; à moins qu’il ne fasse très beau !"))
|
51
|
+
expect("L’ hiver ne va pas durer toute l’année.".ortho).to(eq("L’hiver ne va pas durer toute l’année."))
|
52
|
+
expect("Elle ne disait plus rien…jusqu’au moment du repas.".ortho).to(eq("Elle ne disait plus rien… jusqu’au moment du repas."))
|
53
|
+
expect("Il a dit : «J’arrive ce matin ( ou plus tard ) à Paris [ rue de la République ] pour son anniversaire.»".ortho).to(eq("Il a dit : « J’arrive ce matin (ou plus tard) à Paris [rue de la République] pour son anniversaire. »"))
|
54
|
+
# Le test suivant n'est pas automatisable, parce qu'on ne peut distinguer un Paris-Brest (le gâteau) d'un Paris - Brest (le trajet)
|
55
|
+
# expect("Nous l’avons rencontré à Saint - Martin.".ortho).to(eq("Nous l’avons rencontré à Saint-Martin."))
|
56
|
+
# Le test suivant est-il automatisable ?
|
57
|
+
# expect("Il roule pendant 31, 5km.".ortho).to(eq("Il roule pendant 31,5 km."))
|
58
|
+
# Pas automatisable, rien ne permet de distinguer s'il s'agit d'un rang ou d'un nombre
|
59
|
+
# expect("Il en compte 1,000, 10,000, 36,742, 500,000, puis 1,000,000, 25,000,000, etc.".ortho).to(eq("Il en compte 1 000, 10 000, 36 742, 500 000, puis 1 000 000, 25 000 000, etc."))
|
60
|
+
# expect("Le numéro gagnant est le 3 541 672.".ortho).to(eq("Le numéro gagnant est le 3541672."))
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Orthotypo do
|
4
|
+
it 'selects proper locale' do
|
5
|
+
expect(Orthotypo::Localizer.new('').composer).to be_a Orthotypo::Composer::Fr
|
6
|
+
expect(Orthotypo::Localizer.new('', locale: 'fr').composer).to be_a Orthotypo::Composer::Fr
|
7
|
+
expect(Orthotypo::Localizer.new('', locale: 'fr-FR').composer).to be_a Orthotypo::Composer::FrFr
|
8
|
+
expect(Orthotypo::Localizer.new('', locale: 'fr-CH').composer).to be_a Orthotypo::Composer::FrCh
|
9
|
+
expect(Orthotypo::Localizer.new('', locale: 'en').composer).to be_a Orthotypo::Composer::En
|
10
|
+
expect(Orthotypo::Localizer.new('', locale: 'en-GB').composer).to be_a Orthotypo::Composer::EnGb
|
11
|
+
expect(Orthotypo::Localizer.new('', locale: 'en-UNKNOWN').composer).to be_a Orthotypo::Composer::Fr
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Orthotypo do
|
4
|
+
it 'leaves html entities untouched' do
|
5
|
+
expect("test & test".ortho).to eq "test & test"
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'leaves html tags untouched' do
|
9
|
+
expect("<b>bold</b>".ortho).to eq "<b>bold</b>"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'leaves URLs untouched' do
|
13
|
+
expect("https://unsplash.com/@lusvardi?utm_source=osuny".ortho).to eq "https://unsplash.com/@lusvardi?utm_source=osuny"
|
14
|
+
expect("<a href=\"https://unsplash.com/@lusvardi?utm_source=osuny\">https://unsplash.com/@lusvardi?utm_source=osuny</a>".ortho).to eq "<a href=\"https://unsplash.com/@lusvardi?utm_source=osuny\">https://unsplash.com/@lusvardi?utm_source=osuny</a>"
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'leaves URLs untouched' do
|
18
|
+
expect("prenom.nom@example.com".ortho).to eq "prenom.nom@example.com"
|
19
|
+
expect("<a href=\"mailto:prenom.nom@example.com\">prenom.nom@example.com</a>".ortho).to eq "<a href=\"mailto:prenom.nom@example.com\">prenom.nom@example.com</a>"
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orthotypo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +88,37 @@ email:
|
|
74
88
|
executables: []
|
75
89
|
extensions: []
|
76
90
|
extra_rdoc_files: []
|
77
|
-
files:
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- lib/orthotypo.rb
|
104
|
+
- lib/orthotypo/analyzer.rb
|
105
|
+
- lib/orthotypo/composer.rb
|
106
|
+
- lib/orthotypo/composer/en.rb
|
107
|
+
- lib/orthotypo/composer/en_gb.rb
|
108
|
+
- lib/orthotypo/composer/fr.rb
|
109
|
+
- lib/orthotypo/composer/fr_ch.rb
|
110
|
+
- lib/orthotypo/composer/fr_fr.rb
|
111
|
+
- lib/orthotypo/core_ext.rb
|
112
|
+
- lib/orthotypo/localizer.rb
|
113
|
+
- lib/orthotypo/version.rb
|
114
|
+
- orthotypo.gemspec
|
115
|
+
- sig/orthotypo.rbs
|
116
|
+
- spec/analyzer_spec.rb
|
117
|
+
- spec/composer/en_spec.rb
|
118
|
+
- spec/composer/fr_spec.rb
|
119
|
+
- spec/localizer_spec.rb
|
120
|
+
- spec/orthotypo_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
78
122
|
homepage: https://github.com/noesya/orthotypo
|
79
123
|
licenses:
|
80
124
|
- MIT
|