Move regex out of the loop to improve performance
This commit is contained in:

committed by
vitalets

parent
1159e26e34
commit
4f119f7c73
@ -51,13 +51,15 @@ $(function(){
|
|||||||
if(!html) {
|
if(!html) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var regex = new RegExp(String.fromCharCode(10), 'g');
|
||||||
var lines = html.split(/<br\s*\/?>/i);
|
var lines = html.split(/<br\s*\/?>/i);
|
||||||
for (var i = 0; i < lines.length; i++) {
|
for (var i = 0; i < lines.length; i++) {
|
||||||
var text = $('<div>').html(lines[i]).text();
|
var text = $('<div>').html(lines[i]).text();
|
||||||
|
|
||||||
// Remove newline characters (\n) to avoid them being converted by value2html() method
|
// Remove newline characters (\n) to avoid them being converted by value2html() method
|
||||||
// thus adding extra <br> tags
|
// thus adding extra <br> tags
|
||||||
text = text.replace(new RegExp(String.fromCharCode(10), 'g'), '');
|
text = text.replace(regex, '');
|
||||||
|
|
||||||
lines[i] = text;
|
lines[i] = text;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user