-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.lua
49 lines (39 loc) · 1.16 KB
/
shared.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local shared = {}
local pandocutils = require('pandoc.utils')
function shared.arrayContains(arr, item)
for _, value in ipairs(arr) do
if value == item then
return true
end
end
return false
end
function shared.codeBlockClassesContain(block, classname)
return shared.arrayContains(block.classes, classname)
end
function shared.tableToString(t)
result = ""
for k,v in pairs(t) do
result = result .. tostring(k) .. tostring(v)
end
return result
end
function shared.stringifyAttr(a)
return a.identifier .. shared.tableToString(a.classes) .. shared.tableToString(a.attributes)
end
function shared.stringifyCodeBlock(block)
return shared.stringifyAttr(block.attr) .. block.text
end
function shared.codeBlockSha1(block)
return pandocutils.sha1(shared.stringifyCodeBlock(block))
end
function shared.codeBlockInterpreter(block)
local interpreter = "INTERPRETERNOTFOUND"
if shared.arrayContains(block.classes,"ghcisession") then
interpreter = "ghci"
elseif shared.arrayContains(block.classes,"tidalsession") then
interpreter = "tidal"
end
return interpreter
end
return shared