mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FEATURE: Perform a server side replacement of unicode emoji
This commit is contained in:
parent
98eee2b5de
commit
c064dc1322
2 changed files with 22 additions and 1 deletions
|
@ -246,13 +246,24 @@ module PrettyText
|
|||
end
|
||||
end
|
||||
|
||||
def self.emoji_unicode(text)
|
||||
return text unless SiteSetting.enable_emoji?
|
||||
|
||||
Emoji.db.each do |e|
|
||||
text.gsub!(e['emoji'], ":#{e['aliases'][0]}:")
|
||||
end
|
||||
|
||||
text
|
||||
end
|
||||
|
||||
def self.cook(text, opts={})
|
||||
options = opts.dup
|
||||
|
||||
# we have a minor inconsistency
|
||||
options[:topicId] = opts[:topic_id]
|
||||
|
||||
sanitized = markdown(text.dup, options)
|
||||
working_text = emoji_unicode(text.dup)
|
||||
sanitized = markdown(working_text, options)
|
||||
|
||||
doc = Nokogiri::HTML.fragment(sanitized)
|
||||
|
||||
|
|
|
@ -378,7 +378,17 @@ HTML
|
|||
table = "<table><thead><tr><th>test</th></tr></thead><tbody><tr><td>a</td></tr></tbody></table>"
|
||||
expect(PrettyText.cook(table)).to match_html("")
|
||||
end
|
||||
end
|
||||
|
||||
describe "emoji" do
|
||||
it "replaces unicode emoji with our emoji sets if emoji is enabled" do
|
||||
expect(PrettyText.cook("💣")).to match(/\:bomb\:/)
|
||||
end
|
||||
|
||||
it "doesn't replace unicode emoji if emoji is disabled" do
|
||||
SiteSetting.enable_emoji = false
|
||||
expect(PrettyText.cook("💣")).not_to match(/\:bomb\:/)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue