Browse Source

Merge pull request #9 from dryabov/master

correct support of utf8 hashtags
master
iHedgehog 11 years ago
parent
commit
8b5f55182f
  1. 15
      js/twister_formatpost.js

15
js/twister_formatpost.js

@ -190,7 +190,7 @@ function htmlFormatMsg( msg, output, mentions ) {
if( match[0] == "#" ) { if( match[0] == "#" ) {
output.append($.emotions(msg.substr(0, match.index))); output.append($.emotions(msg.substr(0, match.index)));
tmp = msg.substr(match.index+1); tmp = msg.substr(match.index+1);
var hashtag = _extractUsername(tmp); var hashtag = _extractHashtag(tmp);
if( hashtag.length ) { if( hashtag.length ) {
var hashtagLinkTemplate = $("#hashtag-link-template").clone(true); var hashtagLinkTemplate = $("#hashtag-link-template").clone(true);
hashtagLinkTemplate.removeAttr("id"); hashtagLinkTemplate.removeAttr("id");
@ -225,6 +225,19 @@ function _extractUsername(s) {
return username.toLowerCase(); return username.toLowerCase();
} }
// internal function for htmlFormatMsg
function _extractHashtag(s) {
var hashtag = "";
for( var i = 0; i < s.length; i++ ) {
if( " \n\t.,:/?!".indexOf(s[i]) < 0 ) {
hashtag += s[i];
} else {
break;
}
}
return hashtag;
}
function escapeHtmlEntities(str) { function escapeHtmlEntities(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
} }

Loading…
Cancel
Save