From af445b34d8ec1a6f60cd6eb7c6964e7de450ae83 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 15 Jul 2018 16:02:46 -0700 Subject: [PATCH] Make markdown and github writers respect the `emoji` extension. --- src/Text/Pandoc/Writers/CommonMark.hs | 5 +++++ src/Text/Pandoc/Writers/Markdown.hs | 5 +++++ test/command/emoji.md | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/command/emoji.md diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs index 98c1101fa..27179496c 100644 --- a/src/Text/Pandoc/Writers/CommonMark.hs +++ b/src/Text/Pandoc/Writers/CommonMark.hs @@ -304,6 +304,11 @@ inlineToNodes opts (Math mt str) = (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :) DisplayMath -> (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :) +inlineToNodes opts (Span ("",["emoji"],kvs) [Str s]) = do + case lookup "data-emoji" kvs of + Just emojiname | isEnabled Ext_emoji opts -> + (node (TEXT (":" <> T.pack emojiname <> ":")) [] :) + _ -> (node (TEXT (T.pack s)) [] :) inlineToNodes opts (Span attr ils) = let nodes = inlinesToNodes opts ils op = tagWithAttributes opts True False "span" attr diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index dc0b154bf..c07771384 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -982,6 +982,11 @@ isRight (Left _) = False -- | Convert Pandoc inline element to markdown. inlineToMarkdown :: PandocMonad m => WriterOptions -> Inline -> MD m Doc +inlineToMarkdown opts (Span ("",["emoji"],kvs) [Str s]) = do + case lookup "data-emoji" kvs of + Just emojiname | isEnabled Ext_emoji opts -> + return $ ":" <> text emojiname <> ":" + _ -> inlineToMarkdown opts (Str s) inlineToMarkdown opts (Span attrs ils) = do plain <- asks envPlain contents <- inlineListToMarkdown opts ils diff --git a/test/command/emoji.md b/test/command/emoji.md new file mode 100644 index 000000000..b5c573b3f --- /dev/null +++ b/test/command/emoji.md @@ -0,0 +1,27 @@ +``` +% pandoc -t markdown+emoji -f markdown+emoji +:smile: +^D +:smile: +``` + +``` +% pandoc -t markdown-emoji -f markdown+emoji +:smile: +^D +😄 +``` + +``` +% pandoc -t gfm -f markdown+emoji +:smile: +^D +:smile: +``` + +``` +% pandoc -t gfm-emoji -f markdown+emoji +:smile: +^D +😄 +```