mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
Merge pull request #3920 from tgxworld/fix_onebox_emoji
FIX: Emoji in Discourse onebox is wrapped in square brackets.
This commit is contained in:
commit
c88093eecb
5 changed files with 18 additions and 9 deletions
|
@ -31,7 +31,7 @@ class UserActionSerializer < ApplicationSerializer
|
||||||
|
|
||||||
def excerpt
|
def excerpt
|
||||||
cooked = object.cooked || PrettyText.cook(object.raw)
|
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
|
end
|
||||||
|
|
||||||
def avatar_template
|
def avatar_template
|
||||||
|
|
|
@ -229,7 +229,7 @@ class UserSerializer < BasicUserSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def bio_excerpt
|
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
|
end
|
||||||
|
|
||||||
def include_suspend_reason?
|
def include_suspend_reason?
|
||||||
|
|
|
@ -13,7 +13,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
@text_entities = options[:text_entities] == true
|
@text_entities = options[:text_entities] == true
|
||||||
@markdown_images = options[:markdown_images] == true
|
@markdown_images = options[:markdown_images] == true
|
||||||
@keep_newlines = options[:keep_newlines] == 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
|
@start_excerpt = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,11 +49,14 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
||||||
def start_element(name, attributes=[])
|
def start_element(name, attributes=[])
|
||||||
case name
|
case name
|
||||||
when "img"
|
when "img"
|
||||||
|
|
||||||
attributes = Hash[*attributes.flatten]
|
attributes = Hash[*attributes.flatten]
|
||||||
|
|
||||||
if @keep_emojis && attributes["class"] == 'emoji'
|
if attributes["class"] == 'emoji'
|
||||||
|
if @keep_emoji_images
|
||||||
return include_tag(name, attributes)
|
return include_tag(name, attributes)
|
||||||
|
elsif @keep_emoji_codes
|
||||||
|
return characters(attributes["alt"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# If include_images is set, include the image in markdown
|
# If include_images is set, include the image in markdown
|
||||||
|
|
|
@ -63,7 +63,7 @@ module Onebox
|
||||||
topic = post.topic
|
topic = post.topic
|
||||||
slug = Slug.for(topic.title)
|
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"," ")
|
excerpt.gsub!("\n"," ")
|
||||||
# hack to make it render for now
|
# hack to make it render for now
|
||||||
excerpt.gsub!("[/quote]", "[quote]")
|
excerpt.gsub!("[/quote]", "[quote]")
|
||||||
|
|
|
@ -243,9 +243,14 @@ HTML
|
||||||
expect(PrettyText.excerpt("'", 500, text_entities: true)).to eq("'")
|
expect(PrettyText.excerpt("'", 500, text_entities: true)).to eq("'")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have an option to preserve emojis" do
|
it "should have an option to preserve emoji images" do
|
||||||
emoji_image = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt='heart'>"
|
emoji_image = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt='heart'>"
|
||||||
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 = "<img src='/images/emoji/emoji_one/heart.png?v=1' title=':heart:' class='emoji' alt=':heart:'>"
|
||||||
|
expect(PrettyText.excerpt(emoji_code, 100, { keep_emoji_codes: true })).to eq(":heart:")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue