2

I want to use flag: Japan emoticon with unicode U+1F1EF U+1F1F5 as defined in the standard Full Emoji List, v12.0, inside markdown (rendered with Pandoc).

Given that this Emoticon is not defined inside Pandoc sourcecode: pandoc/Emoji.hs at master · jgm/pandoc, how can I use this inside the document? Or how can I define this in the Pandoc Source Code?

If possible please suggest a general solution that can parse multiple unicode emoji's, such as :thermometer: for 🌡, :jp: for 🇯🇵.

An extensible code would read a csv file or data structure inside lua file:

jp,🇯🇵
thermometer,🌡

and make string substitutions.

2 Answers 2

1

Unless there are counter indications against using the emoji directly, one could simply use the unicode representation.

The alternative would be to add this feature via a pandoc Lua filter. Save the following code into a file flag-jp.lua and pass it to pandoc via --lua-filter=flag-jp.lua. The file must be stored as UTF-8.

function Str (s)
  return pandoc.Str(s.text:gsub(':jp:', '🇯🇵'))
end

The flag can then be inserted by writing :jp: in Markdown.

1
  • Your answer does work! Can I request you if it is possible to make it more general function, in which we could supply multiple custom Emojis. Please see the latest EDIT of the question.
    – Porcupine
    Commented Jul 4, 2019 at 9:29
1

This is more general than @tarleb solution.

ReplacementTable={
      [":jp:"] = "🇯🇵", 
      [":in:"] = "🇮🇳", 
      [":thermometer:"] = "🌡", 
      [":snow_capped_mountain:"] = " 🏔 ", 
      [":beach:"] = " 🏖 ", 
      [":national_park:"] = " 🏞 ", 
      [":money_bag:"] = " 💰 ", 
      [":see_no_evil_monkey:"] = " 🙈 ", 
      [":hear_no_evil_monkey:"] = " 🙉 ", 
      [":speak_no_evil_monkey:"] = " 🙊 "}

function Str (s)
  return pandoc.Str(s.text:gsub("%S+", ReplacementTable))
end
3
  • 1
    Nice! 👍 (first line is duplicated though) It will be a tiny bit faster to define ReplacementTable outside the function.
    – tarleb
    Commented Jul 4, 2019 at 14:17
  • @tarleb Thank you so much! I learnt so much on my first day of lua. But it would be great if our code can use pandoc abstract syntax tree (AST) as this does a stupid replacement of the text. Although it is fine, but it is stupid. I mean that this will blindly replace the text (even if its not meant to be emoji).
    – Porcupine
    Commented Jul 4, 2019 at 16:12
  • 1
    We are using the AST, if in a rather primitive way. This becomes clear if one uses a custom emoji in a code block :beach: : it will not be replaced, as text in code is represented by a different element than other text (Code vs. Str; replace Str with Code in the filter to make it work on inline code). Pandoc handles emoji when reading, which allows to handle :emoji: and \:emoji\: differently. However, both look the same in the AST, so there is no way to distinguish the two in a filter. The smartest way would be to amend pandoc's internal emoji table.
    – tarleb
    Commented Jul 4, 2019 at 20:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .