{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Text.Pandoc.Emoji
   Copyright   : Copyright (C) 2015 John MacFarlane
   License     : GNU GPL, version 2 or above

   Maintainer  : John MacFarlane <jgm@berkeley.edu>
   Stability   : alpha
   Portability : portable

Emoji symbol lookup from canonical string identifier.
-}
module Text.Pandoc.Emoji ( emojis, emojiToInline ) where
import Prelude
import qualified Data.Map as M
import qualified Data.Text as T
import Text.Pandoc.Definition (Inline (Span, Str))
import Text.Pandoc.Emoji.TH (genEmojis)

emojis :: M.Map T.Text T.Text
emojis :: Map Text Text
emojis = [(Text, Text)] -> Map Text Text
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList $(genEmojis "emoji.json")

emojiToInline :: T.Text -> Maybe Inline
emojiToInline :: Text -> Maybe Inline
emojiToInline emojikey :: Text
emojikey = Text -> Inline
makeSpan (Text -> Inline) -> Maybe Text -> Maybe Inline
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Map Text Text -> Maybe Text
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
emojikey Map Text Text
emojis
  where makeSpan :: Text -> Inline
makeSpan = Attr -> [Inline] -> Inline
Span ("", ["emoji"], [("data-emoji", Text
emojikey)]) ([Inline] -> Inline) -> (Text -> [Inline]) -> Text -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[]) (Inline -> [Inline]) -> (Text -> Inline) -> Text -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inline
Str