Emote (emote v0.1.0)

Small lib for converting emoticons and emoji names to emoji characters:

Works with emoji names:

iex> Emote.convert_text("my emoji game is :fire:")
"my emoji game is 🔥"

And emoticons (see lib/emoticons.txt for the list of supported ones):

iex> Emote.convert_text("my emoji game is :P")
"my emoji game is 😜"

You can also provide a list of images that can be used as custom emoji:

iex> Emote.convert_text("I can use images as custom emoji :favicon:",
      custom_emoji: %{"favicon" => "/favicon.ico"}
     )
"I can use images as custom emoji <img class='emoji favicon' alt='favicon' title=':favicon:' src='/favicon.ico' />"

Or your own function to handle custom emoji:

> Emote.convert_text("I can define my own function to handle custom emoji :fire:",
   custom_fn: fn word -> 
    case lookup_my_custom_emoji(word) do
      %{label: label, url: url} ->
          " <img alt='#{label || word}' title='#{label}' class='emoji' data-emoji='#{word}' src='#{url}' /> "
          
      _nil_ ->
          word
      end
   end
  )

Known limitation:

  • Emojis combined together don't work, ex.: ":woo:pile_of_poo:hoo:" would not convert.

License

WTFPL, as originally forked from https://github.com/danigulyas/smile

Summary

Functions

Converts text in a way that it replaces mapped emojis to real emojis.

Converts mapping to emoji, eg ":face_with_ok_gesture:" to 🙆, returns original text when emoji not found, helper function for convert_text.

Functions

Link to this function

convert_text(text, opts \\ [])

Converts text in a way that it replaces mapped emojis to real emojis.

Link to this function

convert_word(word, custom_fn \\ nil)

Converts mapping to emoji, eg ":face_with_ok_gesture:" to 🙆, returns original text when emoji not found, helper function for convert_text.

Link to this function

maybe_custom(text, custom_emoji)

Link to this function

prepare_emoji_code(emoji, file)