From bce5fdfa3ab60ae443fd5ae32424826e9296f59a Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 10 Jul 2022 11:23:10 +0200 Subject: Add support for custom emojis --- filters/emojis.lua | 17 +++++++++++++++++ filters/lib/common.lua | 13 ++++++++++++- filters/vars.lua | 15 +++------------ 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 filters/emojis.lua (limited to 'filters') diff --git a/filters/emojis.lua b/filters/emojis.lua new file mode 100644 index 0000000..5eb9d4b --- /dev/null +++ b/filters/emojis.lua @@ -0,0 +1,17 @@ +local common = require 'filters.lib.common' + +function Str(el) + local prefix, emojiref, suffix = el.text:match('^(.*):([^ ]+):(.*)$') + + if emojiref then + local els = pandoc.List() + + els:insert(pandoc.Str(prefix)) + els:insert(pandoc.Image(emojiref, "/emojis/" .. emojiref .. ".png", emojiref, { class = 'o-emoji' })) + els:insert(pandoc.Str(suffix)) + + return els + end + + return el +end diff --git a/filters/lib/common.lua b/filters/lib/common.lua index 7654eb9..4d44ff3 100644 --- a/filters/lib/common.lua +++ b/filters/lib/common.lua @@ -25,6 +25,17 @@ function dump(o) end end +function string.split(str, sep) + sep = sep or '%s' + + local parts = pandoc.List() + + for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do + parts:insert(field) + if s == "" then return parts end + end +end + return { - wide = wide + wide = wide, dump = dump } diff --git a/filters/vars.lua b/filters/vars.lua index e60019e..b0fa66c 100644 --- a/filters/vars.lua +++ b/filters/vars.lua @@ -1,20 +1,11 @@ -local vars = {} - -function string.split(str, sep) - sep = sep or '%s' - - local parts = pandoc.List() +local common = require 'filters.lib.common' - for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do - parts:insert(field) - if s == "" then return parts end - end -end +local vars = {} function meta(meta) vars = meta end function str(el) - local prefix, varref, suffix = el.text:match('^(.*)%%(.*)%%(.*)$') + local prefix, varref, suffix = el.text:match('^(.*)%%([^ ]+)%%(.*)$') if varref then local parts = varref:split(".") -- cgit v1.2.3-70-g09d2