summaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2021-11-16 17:43:15 +0100
committerVolpeon <git@volpeon.ink>2021-11-16 17:43:15 +0100
commit28527ca2a2336c371966cef441247f11a6805686 (patch)
tree2c940d0cd65116343d05ed75b9e7188e0a7cb133 /filters
parentSlightly smaller cards (diff)
downloadvolpeon.ink-28527ca2a2336c371966cef441247f11a6805686.tar.gz
volpeon.ink-28527ca2a2336c371966cef441247f11a6805686.tar.bz2
volpeon.ink-28527ca2a2336c371966cef441247f11a6805686.zip
Make variables accessible from content files
Diffstat (limited to 'filters')
-rw-r--r--filters/code.lua13
-rw-r--r--filters/common_actions.lua53
-rw-r--r--filters/headers.lua16
-rw-r--r--filters/vars.lua38
4 files changed, 67 insertions, 53 deletions
diff --git a/filters/code.lua b/filters/code.lua
new file mode 100644
index 0000000..aca3ce8
--- /dev/null
+++ b/filters/code.lua
@@ -0,0 +1,13 @@
1function CodeBlock(el)
2 if el.classes[1] == "plain" then
3 el = pandoc.Div({ el }, { class = 's-code' })
4 elseif el.classes[1] then
5 local formatted = pandoc.pipe('pygmentize', {
6 '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight',
7 }, el.text)
8
9 if formatted then el = pandoc.RawBlock('html', formatted) end
10 end
11
12 return el
13end
diff --git a/filters/common_actions.lua b/filters/common_actions.lua
deleted file mode 100644
index cfe2d58..0000000
--- a/filters/common_actions.lua
+++ /dev/null
@@ -1,53 +0,0 @@
1function CodeBlock(el)
2 if el.classes[1] == "plain" then
3 el = pandoc.Div({ el }, { class = 's-code' })
4 elseif el.classes[1] then
5 local formatted = pandoc.pipe('pygmentize', {
6 '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight',
7 }, el.text)
8
9 if formatted then el = pandoc.RawBlock('html', formatted) end
10 end
11
12 return el
13end
14
15function Header(el)
16 if el.level == 1 then
17 local newchildren = pandoc.List()
18 newchildren:insert(pandoc.Span(el.content, { class = 's-headlines__title-inner' }))
19 el.content = newchildren
20 end
21
22 if el.level <= 3 and el.identifier ~= '' then
23 el.content:insert(pandoc.Space())
24 el.content:insert(pandoc.Link(pandoc.RawInline('html',
25 '<svg class="o-icon" width="1em" height="1em"><use href="/symbols.svg#icon-link"></use></svg>'),
26 '#' .. el.identifier, nil, { class = 's-headlines__link' }))
27 end
28
29 return el
30end
31
32function Div(el)
33 if el.attributes.macro == nil then return el end
34
35 if el.attributes.macro == 'refs' and el.content[1].tag == 'BulletList' then
36 local newchildren = pandoc.List()
37
38 newchildren:insert(pandoc.RawBlock('html', '<ul>'))
39
40 for _, children in ipairs(el.content[1].content) do
41 newchildren:insert(pandoc.RawBlock('html',
42 '<li class="c-page__prefixed c-page__prefixed--ref">'))
43 newchildren:extend(children)
44 newchildren:insert(pandoc.RawBlock('html', '</li>'))
45 end
46
47 newchildren:insert(pandoc.RawBlock('html', '</ul>'))
48
49 el.content = newchildren
50 end
51
52 return el.content
53end
diff --git a/filters/headers.lua b/filters/headers.lua
new file mode 100644
index 0000000..4e3a689
--- /dev/null
+++ b/filters/headers.lua
@@ -0,0 +1,16 @@
1function Header(el)
2 if el.level == 1 then
3 local newchildren = pandoc.List()
4 newchildren:insert(pandoc.Span(el.content, { class = 's-headlines__title-inner' }))
5 el.content = newchildren
6 end
7
8 if el.level <= 3 and el.identifier ~= '' then
9 el.content:insert(pandoc.Space())
10 el.content:insert(pandoc.Link(pandoc.RawInline('html',
11 '<svg class="o-icon" width="1em" height="1em"><use href="/symbols.svg#icon-link"></use></svg>'),
12 '#' .. el.identifier, nil, { class = 's-headlines__link' }))
13 end
14
15 return el
16end
diff --git a/filters/vars.lua b/filters/vars.lua
new file mode 100644
index 0000000..e60019e
--- /dev/null
+++ b/filters/vars.lua
@@ -0,0 +1,38 @@
1local vars = {}
2
3function string.split(str, sep)
4 sep = sep or '%s'
5
6 local parts = pandoc.List()
7
8 for field, s in str:gmatch("([^" .. sep .. "]*)(" .. sep .. "?)") do
9 parts:insert(field)
10 if s == "" then return parts end
11 end
12end
13
14function meta(meta) vars = meta end
15
16function str(el)
17 local prefix, varref, suffix = el.text:match('^(.*)%%(.*)%%(.*)$')
18
19 if varref then
20 local parts = varref:split(".")
21 local var = vars
22
23 for i = 1, #parts do
24 local part = parts[i]
25 local v = var[part]
26
27 if not v then return el end
28
29 var = v
30 end
31
32 if var then return pandoc.Str(prefix .. var .. suffix) end
33 end
34
35 return el
36end
37
38return { { Meta = meta }, { Str = str } }