Last active
December 11, 2018 15:31
-
-
Save muks999/954b69d65b65853a6f683d0ad6e1edda to your computer and use it in GitHub Desktop.
Расстановка переносов в html тексте на русском языке
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
/*Вызывается, как и любой 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); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Вызывается, как и любой jquery плагин:
$(function() { $('.article-text').hyphenate(); })
http://vyachet.ru/blog/2014/08/14/hyphen-russian-html-text/
http://jsfiddle.net/swed/94crypw7/