summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-08-02 20:56:45 +0200
committerVolpeon <git@volpeon.ink>2022-08-02 20:56:45 +0200
commit944a735c39a27fc86569c585f2805837b61adb60 (patch)
treec35f9e0c834c35a395aa58edbcebd8b5e9c83d70 /scripts/lib
parentStyle fix for card list 'list' layout gap on <=sm (diff)
downloadvolpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.tar.gz
volpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.tar.bz2
volpeon.ink-944a735c39a27fc86569c585f2805837b61adb60.zip
Slightly tidied up metadata handling
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/common.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/lib/common.lua b/scripts/lib/common.lua
new file mode 100644
index 0000000..80b81ba
--- /dev/null
+++ b/scripts/lib/common.lua
@@ -0,0 +1,54 @@
1function dump(o)
2 if type(o) == 'table' then
3 local s = '{ '
4 for k, v in pairs(o) do
5 if type(k) ~= 'number' then k = '"' .. k .. '"' end
6 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
7 end
8 return s .. '} '
9 else
10 return tostring(o)
11 end
12end
13
14function string.split(str, sep)
15 sep = sep or '%s'
16
17 local parts = pandoc.List()
18
19 for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do
20 parts:insert(field)
21 if s == "" then return parts end
22 end
23end
24
25function pandoc.List:flatten()
26 local result = pandoc.List()
27
28 for i = 1, #self do result:extend(self[i]) end
29
30 return result
31end
32
33function pandoc.List:flatMap(fn)
34 local mapped = self:map(fn)
35 local result = pandoc.List()
36
37 for i = 1, #mapped do result:extend(mapped[i]) end
38
39 return result
40end
41
42function pandoc.List:take(n)
43 if n >= #self then return self end
44
45 local result = pandoc.List()
46
47 for i = 1, n do result:insert(self[i]) end
48
49 return result
50end
51
52return {
53 dump = dump
54}