Browse Source

Fix emojis and linebreaks in nested enitites

master
Igor Zhukov 9 years ago
parent
commit
804b6226bc
  1. 24
      app/js/lib/ng_utils.js

24
app/js/lib/ng_utils.js

@ -1373,6 +1373,14 @@ angular.module('izhukov.utils', [])
if (start >= cStart && start < cEnd || if (start >= cStart && start < cEnd ||
end > cStart && end <= cEnd) { end > cStart && end <= cEnd) {
// console.log('bad', curEntity, newEntity); // console.log('bad', curEntity, newEntity);
if (fromApi &&
start >= cStart && end <= cEnd) {
if (newEntity.nested === undefined) {
newEntity.nested = [];
}
curEntity.offset -= cStart;
newEntity.nested.push(angular.copy(curEntity));
}
bad = true; bad = true;
break; break;
} }
@ -1395,6 +1403,14 @@ angular.module('izhukov.utils', [])
return totalEntities; return totalEntities;
} }
function wrapRichNestedText (text, nested, options) {
if (nested === undefined) {
return encodeEntities(text);
}
return wrapRichText(text, {entities: nested, nested: true});
}
function wrapRichText (text, options) { function wrapRichText (text, options) {
if (!text || !text.length) { if (!text || !text.length) {
return ''; return '';
@ -1518,7 +1534,7 @@ angular.module('izhukov.utils', [])
'<a href="', '<a href="',
encodeEntities(url), encodeEntities(url),
'" target="_blank">', '" target="_blank">',
encodeEntities(entityText), wrapRichNestedText(entityText, entity.nested, options),
'</a>' '</a>'
); );
break; break;
@ -1567,7 +1583,7 @@ angular.module('izhukov.utils', [])
case 'messageEntityBold': case 'messageEntityBold':
html.push( html.push(
'<strong>', '<strong>',
encodeEntities(entityText), wrapRichNestedText(entityText, entity.nested, options),
'</strong>' '</strong>'
); );
break; break;
@ -1575,7 +1591,7 @@ angular.module('izhukov.utils', [])
case 'messageEntityItalic': case 'messageEntityItalic':
html.push( html.push(
'<em>', '<em>',
encodeEntities(entityText), wrapRichNestedText(entityText, entity.nested, options),
'</em>' '</em>'
); );
break; break;
@ -1607,7 +1623,7 @@ angular.module('izhukov.utils', [])
text = $sanitize(html.join('')); text = $sanitize(html.join(''));
if (emojiFound) { if (emojiFound && !options.nested) {
text = text.replace(/\ufe0f|&#65039;|&#65533;|&#8205;/g, '', text); text = text.replace(/\ufe0f|&#65039;|&#65533;|&#8205;/g, '', text);
text = text.replace(/<span class="emoji emoji-(\d)-(\d+)-(\d+)"(.+?)<\/span>/g, text = text.replace(/<span class="emoji emoji-(\d)-(\d+)-(\d+)"(.+?)<\/span>/g,
'<span class="emoji emoji-spritesheet-$1" style="background-position: -$2px -$3px;" $4</span>'); '<span class="emoji emoji-spritesheet-$1" style="background-position: -$2px -$3px;" $4</span>');

Loading…
Cancel
Save