- 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
19 lines
301 B
Ruby
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
|