-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Правило для замены латинских букв на русские
Опечатки, возникающие при переключении клавиатурной раскладки.
- Loading branch information
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ Typograf.groupIndexes = { | |
date: 810, | ||
other: 910, | ||
optalign: 1010, | ||
html: 1110 | ||
typo: 1110, | ||
html: 1210 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(function() { | ||
|
||
var replacements = { | ||
A: 'А', // Latin: Russian | ||
a: 'а', | ||
B: 'В', | ||
E: 'Е', | ||
e: 'е', | ||
K: 'К', | ||
M: 'М', | ||
H: 'Н', | ||
O: 'О', | ||
o: 'о', | ||
P: 'р', | ||
p: 'Р', | ||
C: 'С', | ||
c: 'с', | ||
T: 'Т', | ||
y: 'у', | ||
X: 'Х', | ||
x: 'х' | ||
}; | ||
|
||
var keys = Object.keys(replacements).join(''); | ||
|
||
Typograf.rule({ | ||
name: 'ru/typo/switchingKeyboardLayout', | ||
handler: function(text) { | ||
var re = new RegExp('([' + keys + ']{1,3})(?=[А-ЯЁа-яё]+?)', 'g'); | ||
|
||
return text.replace(re, function(str, $1) { | ||
var result = ''; | ||
for (var i = 0; i < $1.length; i++) { | ||
result += replacements[$1[i]]; | ||
} | ||
|
||
return result; | ||
}); | ||
} | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"en": "Replacement of Latin letters in Russian. Typos occur when you switch keyboard layouts", | ||
"ru": "Замена латинских букв на русские. Опечатки, возникающие при переключении клавиатурной раскладки" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests.push(['ru/typo/switchingKeyboardLayout', [ | ||
[ | ||
'Cпокойствие', // C - latin letter | ||
'Спокойствие' // C - russian letter | ||
], | ||
[ | ||
'Ccылка', // Cc - latin letter | ||
'Ссылка' // Сс - russian letter | ||
], | ||
[ | ||
'Ccылка, ccылка и ещё ccылка', | ||
'Ссылка, ссылка и ещё ссылка' | ||
], | ||
[ | ||
'Первая ccылка\nВторая ccылка\n...\nCедьмая ccылка', | ||
'Первая ссылка\nВторая ссылка\n...\nСедьмая ссылка' | ||
] | ||
]]); |