docbrown/app/labor/emoji_converter.rb
Juan Manuel Ramallo 49c9b5bc87 [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
2019-01-28 16:28:59 -05:00

19 lines
301 B
Ruby

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