FIX: Perform emoji unescape for topic titles in quotes.

This commit is contained in:
Guo Xiang Tan 2017-01-11 17:23:13 +08:00
parent cdd550e947
commit 1758af9a1d
2 changed files with 21 additions and 3 deletions

View File

@ -1,9 +1,18 @@
import { register } from 'pretty-text/engines/discourse-markdown/bbcode'; import { register } from 'pretty-text/engines/discourse-markdown/bbcode';
import { registerOption } from 'pretty-text/pretty-text';
import { performEmojiUnescape } from 'pretty-text/emoji';
registerOption((siteSettings, opts) => {
opts.enableEmoji = siteSettings.enable_emoji;
opts.emojiSet = siteSettings.emoji_set;
});
export function setup(helper) { export function setup(helper) {
register(helper, 'quote', {noWrap: true, singlePara: true}, (contents, bbParams, options) => { register(helper, 'quote', {noWrap: true, singlePara: true}, (contents, bbParams, options) => {
const params = {'class': 'quote'}; const params = {'class': 'quote'};
let username = null; let username = null;
const opts = helper.getOptions();
if (bbParams) { if (bbParams) {
const paramsSplit = bbParams.split(/\,\s*/); const paramsSplit = bbParams.split(/\,\s*/);
@ -52,7 +61,16 @@ export function setup(helper) {
if (postNumber > 0) { href += "/" + postNumber; } if (postNumber > 0) { href += "/" + postNumber; }
// get rid of username said stuff // get rid of username said stuff
header.pop(); header.pop();
header.push(['a', {'href': href}, topicInfo.title]);
let title = topicInfo.title;
if (opts.enableEmoji) {
title = performEmojiUnescape(topicInfo.title, {
getURL: opts.getURL, emojiSet: opts.emojiSet
});
}
header.push(['a', {'href': href}, title]);
} }
} }

View File

@ -10,10 +10,10 @@ describe PrettyText do
describe "off topic quoting" do describe "off topic quoting" do
it "can correctly populate topic title" do it "can correctly populate topic title" do
topic = Fabricate(:topic, title: "this is a test topic") topic = Fabricate(:topic, title: "this is a test topic :slight_smile:")
expected = <<HTML expected = <<HTML
<aside class="quote" data-post="2" data-topic="#{topic.id}"><div class="title"> <aside class="quote" data-post="2" data-topic="#{topic.id}"><div class="title">
<div class="quote-controls"></div><a href="http://test.localhost/t/this-is-a-test-topic/#{topic.id}/2">This is a test topic</a> <div class="quote-controls"></div><a href="http://test.localhost/t/this-is-a-test-topic-slight-smile/#{topic.id}/2">This is a test topic <img src="/images/emoji/emoji_one/slight_smile.png?v=3" title="slight_smile" alt="slight_smile" class="emoji"></a>
</div> </div>
<blockquote><p>ddd</p></blockquote></aside> <blockquote><p>ddd</p></blockquote></aside>
HTML HTML