skip too short syntax highlighting matches

This commit is contained in:
Hannes Mannerheim 2015-09-19 22:17:22 +02:00
parent ce79f407ea
commit 66124e5fa0

View File

@ -2485,6 +2485,14 @@ $('body').on('keyup paste input', 'div.queet-box-syntax', function() {
var i = 0;
while(currentVal.match(v) && i < 100) { // 100 matches is enough, we don't want to get caught in an infinite loop here
var currentMatch = currentVal.match(v);
// too small match, probably a single ! or something, just replace that with its html code
if($.trim(currentMatch[0]).length < 2) {
currentVal = currentVal.replace(currentMatch[0],currentMatch[0].replace('#','&#35;').replace('@','&#64;').replace('.','&#046;').replace('!','&#33;'));
}
// long enough match, create a mention span
else {
// don't include ending char, if any of these
if(currentMatch[0].slice(-1) == '<'
|| currentMatch[0].slice(-1) == '&'
|| currentMatch[0].slice(-1) == '?'
@ -2497,6 +2505,7 @@ $('body').on('keyup paste input', 'div.queet-box-syntax', function() {
currentMatch[0] = currentMatch[0].slice(0,-1);
}
currentVal = currentVal.replace(currentMatch[0],'<span class="' + k + '">' + currentMatch[0].replace('#','&#35;').replace('@','&#64;').replace('.','&#046;').replace('!','&#33;') + '</span>')
}
i++;
}
});