[Emojis in Markdown] (#1653)

- Adds the ability to add emojis using colons 😂 🎉
- The emoji conversion is added to the markdown parser labor
- When no emoji is found with the alias, same text is returned
- No assets added (no emoji images), so this will only be supported when the browser supports emojis (https://blog.getemoji.com/post/57054354336/which-browsers-support-emoji)
- Emoji conversion logic is out of markdown parser labor
- Adds its own spec
This commit is contained in:
Juan Manuel Ramallo 2019-01-28 18:28:59 -03:00 committed by Ben Halpern
parent ea63374408
commit 49c9b5bc87
5 changed files with 42 additions and 0 deletions

View file

@ -46,6 +46,7 @@ gem "feedjira", "~> 2.2"
gem "figaro", "~> 1.1"
gem "fog", "~> 1.41"
gem "front_matter_parser", "~> 0.2"
gem "gemoji", "~> 3.0.0"
gem "gibbon", "~> 2.2"
gem "google-api-client", "~> 0.27"
gem "honeycomb-rails"

View file

@ -450,6 +450,7 @@ GEM
fugit (1.1.6)
et-orbi (~> 1.1, >= 1.1.6)
raabro (~> 1.1)
gemoji (3.0.0)
get_process_mem (0.2.3)
gibbon (2.2.5)
faraday (>= 0.9.1)
@ -964,6 +965,7 @@ DEPENDENCIES
fix-db-schema-conflicts!
fog (~> 1.41)
front_matter_parser (~> 0.2)
gemoji (~> 3.0.0)
gibbon (~> 2.2)
google-api-client (~> 0.27)
guard (~> 2.15)

View file

@ -0,0 +1,19 @@
class EmojiConverter
attr_reader :html
def self.call(html)
new(html).convert
end
def initialize(html)
@html = html
end
def convert
html.gsub!(/:([\w+-]+):/) do |match|
emoji = Emoji.find_by_alias($1)
emoji.present? ? emoji.raw : match
end
html
end
end

View file

@ -24,6 +24,7 @@ class MarkdownParser
html = wrap_all_images_in_links(html)
html = wrap_all_tables(html)
html = remove_empty_paragraphs(html)
html = EmojiConverter.call(html)
wrap_mentions_with_links!(html)
end

View file

@ -0,0 +1,19 @@
require "rails_helper"
RSpec.describe EmojiConverter do
def convert_emoji(html)
EmojiConverter.call(html)
end
describe "#convert" do
it "converts emoji names wrapped in colons into unicode" do
joy_emoji_unicode = Emoji.find_by_alias("joy").raw
expect(convert_emoji(":joy:")).to include(joy_emoji_unicode)
end
it "leaves original text between colons when no emoji is found" do
emoji_text = ":no_one_will_ever_create_an_emoji_with_this_alias:"
expect(convert_emoji(emoji_text)).to include(emoji_text)
end
end
end