Make markdown and github writers respect the emoji extension.

This commit is contained in:
John MacFarlane 2018-07-15 16:02:46 -07:00
parent ec30fb37c1
commit af445b34d8
3 changed files with 37 additions and 0 deletions

View file

@ -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

View file

@ -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

27
test/command/emoji.md Normal file
View file

@ -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
😄
```