FIX: All unicode replacements beside words. Omit some symbols.

This commit is contained in:
Robin Ward 2016-03-09 14:59:36 -05:00
parent 566b0bbb75
commit 616006a9ce
2 changed files with 11 additions and 3 deletions

View File

@ -169,7 +169,15 @@ Discourse.Dialect.addPreProcessor(function(text) {
var m; var m;
while ((m = _unicodeRegexp.exec(text)) !== null) { while ((m = _unicodeRegexp.exec(text)) !== null) {
text = text.replace(m[0], ":" + _unicodeReplacements[m[0]] + ":");
var replacement = ":" + _unicodeReplacements[m[0]] + ":";
var before = text.charAt(m.index-1);
if (!/\B/.test(before)) {
replacement = " " + replacement;
}
text = text.replace(m[0], replacement);
} }
} }

View File

@ -131,8 +131,8 @@ class Emoji
@unicode_replacements = {} @unicode_replacements = {}
db['emojis'].each do |e| db['emojis'].each do |e|
hex = e['code'].hex hex = e['code'].hex
# Don't replace digits or letters # Don't replace digits, letters and some symbols
if hex > 128 if hex > 255 && e['name'] != 'tm'
@unicode_replacements[[hex].pack('U')] = e['name'] @unicode_replacements[[hex].pack('U')] = e['name']
end end
end end