From 87b52e4ceaad2c611f8c09969fadf48c9fc049c1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 20 Jul 2016 16:45:48 -0400 Subject: [PATCH] FIX: Support emoji in "Popular Links" --- app/assets/javascripts/discourse/widgets/emoji.js.es6 | 8 +++++++- .../javascripts/discourse/widgets/post-links.js.es6 | 6 ++---- app/assets/javascripts/discourse/widgets/topic-map.js.es6 | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/emoji.js.es6 b/app/assets/javascripts/discourse/widgets/emoji.js.es6 index 2eb66d93682..5550af6a2e6 100644 --- a/app/assets/javascripts/discourse/widgets/emoji.js.es6 +++ b/app/assets/javascripts/discourse/widgets/emoji.js.es6 @@ -1,5 +1,11 @@ import { createWidget } from 'discourse/widgets/widget'; -import { emojiUrlFor } from 'discourse/lib/text'; +import { emojiUrlFor, emojiUnescape } from 'discourse/lib/text'; +import RawHtml from 'discourse/widgets/raw-html'; + +export function replaceEmoji(str) { + const escaped = emojiUnescape(Handlebars.Utils.escapeExpression(str)); + return [new RawHtml({ html: `${escaped}` })]; +} export default createWidget('emoji', { tagName: 'img.emoji', diff --git a/app/assets/javascripts/discourse/widgets/post-links.js.es6 b/app/assets/javascripts/discourse/widgets/post-links.js.es6 index c607a84cb3a..3d5b8f871f1 100644 --- a/app/assets/javascripts/discourse/widgets/post-links.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-links.js.es6 @@ -1,8 +1,7 @@ import { iconNode } from 'discourse/helpers/fa-icon'; import { createWidget } from 'discourse/widgets/widget'; import { h } from 'virtual-dom'; -import RawHtml from 'discourse/widgets/raw-html'; -import { emojiUnescape } from 'discourse/lib/text'; +import { replaceEmoji } from 'discourse/widgets/emoji'; export default createWidget('post-links', { tagName: 'div.post-links-container', @@ -13,8 +12,7 @@ export default createWidget('post-links', { }, linkHtml(link) { - const escapedTitle = emojiUnescape(Handlebars.Utils.escapeExpression(link.title)); - const linkBody = [new RawHtml({ html: `${escapedTitle}` })]; + const linkBody = replaceEmoji(link.title); if (link.clicks) { linkBody.push(h('span.badge.badge-notification.clicks', link.clicks.toString())); } diff --git a/app/assets/javascripts/discourse/widgets/topic-map.js.es6 b/app/assets/javascripts/discourse/widgets/topic-map.js.es6 index c219f2a085e..675e8b9d3a3 100644 --- a/app/assets/javascripts/discourse/widgets/topic-map.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-map.js.es6 @@ -2,6 +2,7 @@ import { createWidget } from 'discourse/widgets/widget'; import { h } from 'virtual-dom'; import { avatarImg, avatarFor } from 'discourse/widgets/post'; import { dateNode, numberNode } from 'discourse/helpers/node'; +import { replaceEmoji } from 'discourse/widgets/emoji'; const LINKS_SHOWN = 5; @@ -115,8 +116,7 @@ createWidget('topic-map-link', { }, html(attrs) { - if (attrs.title) { return attrs.title; } - return attrs.url; + return attrs.title ? replaceEmoji(attrs.title) : attrs.url; } });