git.iko.soy/typeable/pandoc
on master help sign in
Make markdown and github writers respect the `emoji` extension.
commitaf445b34d8ec1a6f60cd6eb7c6964e7de450ae83 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 15 Jul 2018, 16:02 (8 years ago) parentec30fb3
3 files changed+37
src/Text/Pandoc/Writers/CommonMark.hs+5 src/Text/Pandoc/Writers/Markdown.hs+5 test/command/emoji.md+27
src/Text/Pandoc/Writers/CommonMark.hs+5
@@ -304,6 +304,11 @@ inlineToNodes opts (Math mt str) =
304304 (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :)
305305 DisplayMath ->
306306 (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :)
307+inlineToNodes opts (Span ("",["emoji"],kvs) [Str s]) = do
308+ case lookup "data-emoji" kvs of
309+ Just emojiname | isEnabled Ext_emoji opts ->
310+ (node (TEXT (":" <> T.pack emojiname <> ":")) [] :)
311+ _ -> (node (TEXT (T.pack s)) [] :)
307312inlineToNodes opts (Span attr ils) =
308313 let nodes = inlinesToNodes opts ils
309314 op = tagWithAttributes opts True False "span" attr
src/Text/Pandoc/Writers/Markdown.hs+5
@@ -982,6 +982,11 @@ isRight (Left _) = False
982982
983983-- | Convert Pandoc inline element to markdown.
984984inlineToMarkdown :: PandocMonad m => WriterOptions -> Inline -> MD m Doc
985+inlineToMarkdown opts (Span ("",["emoji"],kvs) [Str s]) = do
986+ case lookup "data-emoji" kvs of
987+ Just emojiname | isEnabled Ext_emoji opts ->
988+ return $ ":" <> text emojiname <> ":"
989+ _ -> inlineToMarkdown opts (Str s)
985990inlineToMarkdown opts (Span attrs ils) = do
986991 plain <- asks envPlain
987992 contents <- inlineListToMarkdown opts ils
test/command/emoji.mdnew file+27
@@ -0,0 +1,27 @@
1+```
2+% pandoc -t markdown+emoji -f markdown+emoji
3+:smile:
4+^D
5+:smile:
6+```
7+
8+```
9+% pandoc -t markdown-emoji -f markdown+emoji
10+:smile:
11+^D
12+๐Ÿ˜„
13+```
14+
15+```
16+% pandoc -t gfm -f markdown+emoji
17+:smile:
18+^D
19+:smile:
20+```
21+
22+```
23+% pandoc -t gfm-emoji -f markdown+emoji
24+:smile:
25+^D
26+๐Ÿ˜„
27+```