Skip to content

Instantly share code, notes, and snippets.

@muks999
Last active December 11, 2018 15:31
Show Gist options
  • Save muks999/954b69d65b65853a6f683d0ad6e1edda to your computer and use it in GitHub Desktop.
Save muks999/954b69d65b65853a6f683d0ad6e1edda to your computer and use it in GitHub Desktop.
Расстановка переносов в html тексте на русском языке
/*Вызывается, как и любой jquery плагин:
$(function() { $('.article-text').hyphenate(); })
http://vyachet.ru/blog/2014/08/14/hyphen-russian-html-text/ -ссылка на оригинал статьи
http://jsfiddle.net/swed/94crypw7/ -демонстрация работы плагина*/
$.fn.hyphenate = function() {
var all = "[абвгдеёжзийклмнопрстуфхцчшщъыьэюя]",
glas = "[аеёиоуыэю\я]",
sogl = "[бвгджзклмнпрстфхцчшщ]",
zn = "[йъь]",
shy = "\xAD",
re = [];
re[1] = new RegExp("("+zn+")("+all+all+")","ig");
re[2] = new RegExp("("+glas+")("+glas+all+")","ig");
re[3] = new RegExp("("+glas+sogl+")("+sogl+glas+")","ig");
re[4] = new RegExp("("+sogl+glas+")("+sogl+glas+")","ig");
re[5] = new RegExp("("+glas+sogl+")("+sogl+sogl+glas+")","ig");
re[6] = new RegExp("("+glas+sogl+sogl+")("+sogl+sogl+glas+")","ig");
return this.each(function() {
var text = $(this).html();
for (var i = 1; i < 7; ++i) {
text = text.replace(re[i], "$1"+shy+"$2");
}
$(this).html(text);
});
};
@muks999
Copy link
Author

muks999 commented Sep 23, 2016

Вызывается, как и любой jquery плагин:

$(function() { $('.article-text').hyphenate(); })

http://vyachet.ru/blog/2014/08/14/hyphen-russian-html-text/
http://jsfiddle.net/swed/94crypw7/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment