diff --git a/app/serializers/user_action_serializer.rb b/app/serializers/user_action_serializer.rb
index d9609ff9b..965f4e61e 100644
--- a/app/serializers/user_action_serializer.rb
+++ b/app/serializers/user_action_serializer.rb
@@ -31,7 +31,7 @@ class UserActionSerializer < ApplicationSerializer
def excerpt
cooked = object.cooked || PrettyText.cook(object.raw)
- PrettyText.excerpt(cooked, 300, keep_emojis: true) if cooked
+ PrettyText.excerpt(cooked, 300, keep_emoji_images: true) if cooked
end
def avatar_template
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb
index 06abd889a..480fbd9c6 100644
--- a/app/serializers/user_serializer.rb
+++ b/app/serializers/user_serializer.rb
@@ -229,7 +229,7 @@ class UserSerializer < BasicUserSerializer
end
def bio_excerpt
- object.user_profile.bio_excerpt(350 , { keep_newlines: true, keep_emojis: true })
+ object.user_profile.bio_excerpt(350 , { keep_newlines: true, keep_emoji_images: true })
end
def include_suspend_reason?
diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb
index 95e9cf1de..acfa88b88 100644
--- a/lib/excerpt_parser.rb
+++ b/lib/excerpt_parser.rb
@@ -13,7 +13,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
@text_entities = options[:text_entities] == true
@markdown_images = options[:markdown_images] == true
@keep_newlines = options[:keep_newlines] == true
- @keep_emojis = options[:keep_emojis] == true
+ @keep_emoji_images = options[:keep_emoji_images] == true
+ @keep_emoji_codes = options[:keep_emoji_codes] == true
@start_excerpt = false
end
@@ -48,11 +49,14 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
def start_element(name, attributes=[])
case name
when "img"
-
attributes = Hash[*attributes.flatten]
- if @keep_emojis && attributes["class"] == 'emoji'
- return include_tag(name, attributes)
+ if attributes["class"] == 'emoji'
+ if @keep_emoji_images
+ return include_tag(name, attributes)
+ elsif @keep_emoji_codes
+ return characters(attributes["alt"])
+ end
end
# If include_images is set, include the image in markdown
diff --git a/lib/onebox/engine/discourse_local_onebox.rb b/lib/onebox/engine/discourse_local_onebox.rb
index 5fd48971b..cac4503d6 100644
--- a/lib/onebox/engine/discourse_local_onebox.rb
+++ b/lib/onebox/engine/discourse_local_onebox.rb
@@ -63,7 +63,7 @@ module Onebox
topic = post.topic
slug = Slug.for(topic.title)
- excerpt = post.excerpt(SiteSetting.post_onebox_maxlength)
+ excerpt = post.excerpt(SiteSetting.post_onebox_maxlength, { keep_emoji_codes: true })
excerpt.gsub!("\n"," ")
# hack to make it render for now
excerpt.gsub!("[/quote]", "[quote]")
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index dabe28405..0cca316e1 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -243,9 +243,14 @@ HTML
expect(PrettyText.excerpt("'", 500, text_entities: true)).to eq("'")
end
- it "should have an option to preserve emojis" do
+ it "should have an option to preserve emoji images" do
emoji_image = ""
- expect(PrettyText.excerpt(emoji_image, 100, { keep_emojis: true })).to match_html(emoji_image)
+ expect(PrettyText.excerpt(emoji_image, 100, { keep_emoji_images: true })).to match_html(emoji_image)
+ end
+
+ it "should have an option to preserve emoji codes" do
+ emoji_code = ""
+ expect(PrettyText.excerpt(emoji_code, 100, { keep_emoji_codes: true })).to eq(":heart:")
end
end