polytypo 1.20.0 → 1.21.0
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/lib/polytypo/data/VERSION +1 -1
- data/lib/polytypo/data/fixtures/bg.json +12 -1
- data/lib/polytypo/data/fixtures/cs.json +12 -1
- data/lib/polytypo/data/fixtures/de-CH.json +12 -1
- data/lib/polytypo/data/fixtures/de-DE.json +12 -1
- data/lib/polytypo/data/fixtures/el.json +12 -1
- data/lib/polytypo/data/fixtures/en-GB.json +12 -1
- data/lib/polytypo/data/fixtures/en-US.json +403 -1
- data/lib/polytypo/data/fixtures/es.json +12 -1
- data/lib/polytypo/data/fixtures/fi.json +12 -1
- data/lib/polytypo/data/fixtures/fr-CA.json +12 -1
- data/lib/polytypo/data/fixtures/fr.json +12 -1
- data/lib/polytypo/data/fixtures/hr.json +12 -1
- data/lib/polytypo/data/fixtures/hu.json +12 -1
- data/lib/polytypo/data/fixtures/it.json +12 -1
- data/lib/polytypo/data/fixtures/locale-resolution.json +1 -1
- data/lib/polytypo/data/fixtures/lt.json +12 -1
- data/lib/polytypo/data/fixtures/nl.json +12 -1
- data/lib/polytypo/data/fixtures/pl.json +12 -1
- data/lib/polytypo/data/fixtures/pt-BR.json +12 -1
- data/lib/polytypo/data/fixtures/pt-PT.json +12 -1
- data/lib/polytypo/data/fixtures/ro.json +12 -1
- data/lib/polytypo/data/fixtures/ru.json +12 -1
- data/lib/polytypo/data/fixtures/sk.json +12 -1
- data/lib/polytypo/data/fixtures/sl.json +12 -1
- data/lib/polytypo/data/fixtures/sr.json +12 -1
- data/lib/polytypo/data/fixtures/sv.json +12 -1
- data/lib/polytypo/data/fixtures/tr.json +12 -1
- data/lib/polytypo/data/fixtures/uk.json +12 -1
- data/lib/polytypo/data/locales/bg.json +1 -0
- data/lib/polytypo/data/locales/cs.json +1 -0
- data/lib/polytypo/data/locales/de-CH.json +6 -0
- data/lib/polytypo/data/locales/de-DE.json +7 -0
- data/lib/polytypo/data/locales/el.json +1 -0
- data/lib/polytypo/data/locales/en-GB.json +7 -0
- data/lib/polytypo/data/locales/en-US.json +7 -0
- data/lib/polytypo/data/locales/es.json +1 -0
- data/lib/polytypo/data/locales/fi.json +1 -0
- data/lib/polytypo/data/locales/fr-CA.json +1 -0
- data/lib/polytypo/data/locales/fr.json +1 -0
- data/lib/polytypo/data/locales/hr.json +1 -0
- data/lib/polytypo/data/locales/hu.json +1 -0
- data/lib/polytypo/data/locales/it.json +1 -0
- data/lib/polytypo/data/locales/lt.json +1 -0
- data/lib/polytypo/data/locales/nl.json +1 -0
- data/lib/polytypo/data/locales/pl.json +1 -0
- data/lib/polytypo/data/locales/pt-BR.json +1 -0
- data/lib/polytypo/data/locales/pt-PT.json +1 -0
- data/lib/polytypo/data/locales/registry.json +1 -1
- data/lib/polytypo/data/locales/ro.json +1 -0
- data/lib/polytypo/data/locales/ru.json +1 -0
- data/lib/polytypo/data/locales/sk.json +1 -0
- data/lib/polytypo/data/locales/sl.json +1 -0
- data/lib/polytypo/data/locales/sr.json +2 -1
- data/lib/polytypo/data/locales/sv.json +1 -0
- data/lib/polytypo/data/locales/tr.json +1 -0
- data/lib/polytypo/data/locales/uk.json +1 -0
- data/lib/polytypo/data/rules/order.json +9 -1
- data/lib/polytypo/data/rules/pipeline-idempotency.md +23 -3
- data/lib/polytypo/data/rules/quote-punctuation.md +334 -0
- data/lib/polytypo/data/rules/quotes.md +9 -0
- data/lib/polytypo/data/schema/fixtures.schema.json +1 -0
- data/lib/polytypo/data/schema/locale.schema.json +12 -1
- data/lib/polytypo/engine/locale.rb +22 -1
- data/lib/polytypo/engine/pipeline.rb +1 -1
- data/lib/polytypo/engine/rules/quote_punctuation.rb +79 -0
- data/lib/polytypo/engine/rules.rb +1 -0
- data/lib/polytypo/version.rb +1 -1
- metadata +3 -1
|
@@ -94,7 +94,7 @@ module Polytypo
|
|
|
94
94
|
# spec data in Registry/Locale (ARCHITECTURE.md section 7).
|
|
95
95
|
module Pipeline
|
|
96
96
|
# Defaults + opt-out overrides. rules_option is opt-out only (ARCHITECTURE.md section 7):
|
|
97
|
-
# it may only disable a default-on rule or enable
|
|
97
|
+
# it may only disable a default-on rule or enable a default-off one ("ranges", "quote-punctuation"). An
|
|
98
98
|
# unknown key raises POLYTYPO_UNKNOWN_RULE.
|
|
99
99
|
def self.resolve_rule_plan(rules_option)
|
|
100
100
|
defaults = Registry.rule_defaults
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "quote_ambiguity"
|
|
4
|
+
require_relative "../sentinels"
|
|
5
|
+
require_relative "../unicode_util"
|
|
6
|
+
require_relative "../edits"
|
|
7
|
+
require_relative "../registry"
|
|
8
|
+
|
|
9
|
+
module Polytypo
|
|
10
|
+
module Engine
|
|
11
|
+
module Rules
|
|
12
|
+
# `quote-punctuation` -- spec/rules/quote-punctuation.md (spec 1.21.0), order 45, off by
|
|
13
|
+
# default.
|
|
14
|
+
#
|
|
15
|
+
# Moves a comma or a full stop from after the locale's closing primary quotation mark to
|
|
16
|
+
# before it, only where `quotes.punctuationPlacement` is "inside". One left-to-right scan
|
|
17
|
+
# over code points; every edit swaps two adjacent code points, so the text never changes
|
|
18
|
+
# length and no regex or normalization is involved. The inline marker is in no class below,
|
|
19
|
+
# so a span boundary or protected run on any of the three sides declines the move.
|
|
20
|
+
module QuotePunctuation
|
|
21
|
+
COMMA = 0x2C
|
|
22
|
+
FULL_STOP = 0x2E
|
|
23
|
+
|
|
24
|
+
# SPACELIKE (quotes.md 3.1): INLINE-SPACE plus BREAK, with Engine::LINE_MARKER a member of
|
|
25
|
+
# BREAK for every rule (modes.md 3.2).
|
|
26
|
+
BREAK = [0x0A, 0x0D, 0x0B, 0x0C, 0x85, 0x2028, 0x2029, Engine::LINE_MARKER].freeze
|
|
27
|
+
|
|
28
|
+
def self.spacelike?(cp)
|
|
29
|
+
QuoteAmbiguity.inline_space?(cp) || BREAK.include?(cp)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# cp[i], or NONE if i is out of bounds -- the spec's own boundary value.
|
|
33
|
+
def self.at(cp, i)
|
|
34
|
+
return NONE if i.negative? || i >= cp.length
|
|
35
|
+
|
|
36
|
+
cp[i]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# quote-punctuation.md 3.2: C1-C4 for the pair at i, i + 1.
|
|
40
|
+
def self.edit_at?(cp, i, close)
|
|
41
|
+
return false unless cp[i] == close && i >= 1
|
|
42
|
+
|
|
43
|
+
next_cp = cp[i + 1]
|
|
44
|
+
return false unless next_cp == COMMA || next_cp == FULL_STOP
|
|
45
|
+
return false unless UnicodeUtil.letter?(cp[i - 1])
|
|
46
|
+
|
|
47
|
+
after = at(cp, i + 2)
|
|
48
|
+
after == NONE || spacelike?(after)
|
|
49
|
+
end
|
|
50
|
+
private_class_method :edit_at?
|
|
51
|
+
|
|
52
|
+
def self.scan(cp, locale_data, _ctx)
|
|
53
|
+
quotes = locale_data["quotes"]
|
|
54
|
+
return [] unless quotes["punctuationPlacement"] == "inside"
|
|
55
|
+
|
|
56
|
+
close = quotes["primary"]["close"].codepoints.first
|
|
57
|
+
return [] if close.nil?
|
|
58
|
+
|
|
59
|
+
edits = []
|
|
60
|
+
i = 0
|
|
61
|
+
while i + 1 < cp.length
|
|
62
|
+
if edit_at?(cp, i, close)
|
|
63
|
+
edits << Edit.new(i, i + 2, [cp[i + 1], close], "quote-punctuation")
|
|
64
|
+
i += 2
|
|
65
|
+
else
|
|
66
|
+
i += 1
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
edits
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
Polytypo::Engine::Registry.register(
|
|
77
|
+
"quote-punctuation",
|
|
78
|
+
->(cp, locale_data, ctx) { Polytypo::Engine::Rules::QuotePunctuation.scan(cp, locale_data, ctx) },
|
|
79
|
+
)
|
|
@@ -14,6 +14,7 @@ require_relative "rules/ranges"
|
|
|
14
14
|
require_relative "rules/dashes"
|
|
15
15
|
require_relative "rules/hyphen"
|
|
16
16
|
require_relative "rules/quotes"
|
|
17
|
+
require_relative "rules/quote_punctuation"
|
|
17
18
|
require_relative "rules/apostrophe"
|
|
18
19
|
require_relative "rules/symbols"
|
|
19
20
|
require_relative "rules/nbsp"
|
data/lib/polytypo/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polytypo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Iurii Rogulia
|
|
@@ -106,6 +106,7 @@ files:
|
|
|
106
106
|
- lib/polytypo/data/rules/nbsp.md
|
|
107
107
|
- lib/polytypo/data/rules/order.json
|
|
108
108
|
- lib/polytypo/data/rules/pipeline-idempotency.md
|
|
109
|
+
- lib/polytypo/data/rules/quote-punctuation.md
|
|
109
110
|
- lib/polytypo/data/rules/quotes.md
|
|
110
111
|
- lib/polytypo/data/rules/ranges.md
|
|
111
112
|
- lib/polytypo/data/rules/spaces.md
|
|
@@ -130,6 +131,7 @@ files:
|
|
|
130
131
|
- lib/polytypo/engine/rules/hyphen.rb
|
|
131
132
|
- lib/polytypo/engine/rules/nbsp.rb
|
|
132
133
|
- lib/polytypo/engine/rules/quote_ambiguity.rb
|
|
134
|
+
- lib/polytypo/engine/rules/quote_punctuation.rb
|
|
133
135
|
- lib/polytypo/engine/rules/quotes.rb
|
|
134
136
|
- lib/polytypo/engine/rules/ranges.rb
|
|
135
137
|
- lib/polytypo/engine/rules/spaces.rb
|