FIX: winky emoticons were matching with non-spaces before them.

This commit is contained in:
Robin Ward
2014-06-04 15:48:08 -04:00
parent 535c90c298
commit d46fc79344
2 changed files with 16 additions and 11 deletions

View File

@@ -182,8 +182,8 @@ Discourse.Dialect = {
@param {Function} emitter A function that emits the JsonML for the replacement. @param {Function} emitter A function that emits the JsonML for the replacement.
**/ **/
inlineReplace: function(token, emitter) { inlineReplace: function(token, emitter) {
this.registerInline(token, function() { this.registerInline(token, function(text, match, prev) {
return [token.length, emitter.call(this, token)]; return [token.length, emitter.call(this, token, match, prev)];
}); });
}, },

View File

@@ -37,14 +37,25 @@
":-$" : 'blush' ":-$" : 'blush'
}; };
function checkPrev(prev) {
if (prev && prev.length) {
var lastToken = prev[prev.length-1];
if (lastToken && lastToken.charAt) {
var lastChar = lastToken.charAt(lastToken.length-1);
if (lastChar !== ' ') return false;
}
}
return true;
}
var translationsWithColon = {}; var translationsWithColon = {};
Object.keys(translations).forEach(function (t) { Object.keys(translations).forEach(function (t) {
if (t[0] === ':') { if (t[0] === ':') {
translationsWithColon[t] = translations[t]; translationsWithColon[t] = translations[t];
} else { } else {
var replacement = translations[t]; var replacement = translations[t];
Discourse.Dialect.inlineReplace(t, function () { Discourse.Dialect.inlineReplace(t, function (token, match, prev) {
return imageFor(replacement); return checkPrev(prev) ? imageFor(replacement) : token;
}); });
} }
}); });
@@ -64,13 +75,7 @@
firstSpace = text.search(/\s/), firstSpace = text.search(/\s/),
contents; contents;
if (prev && prev.length) { if (!checkPrev(prev)) { return; }
var lastToken = prev[prev.length-1];
if (lastToken && lastToken.charAt) {
var lastChar = lastToken.charAt(lastToken.length-1);
if (lastChar !== ' ') return;
}
}
// If there is no trailing colon, check our translations that begin with colons // If there is no trailing colon, check our translations that begin with colons
if (endPos === -1 || (firstSpace !== -1 && endPos > firstSpace)) { if (endPos === -1 || (firstSpace !== -1 && endPos > firstSpace)) {