summaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
Diffstat (limited to 'filters')
-rw-r--r--filters/code.lua15
-rw-r--r--filters/headers.lua9
-rw-r--r--filters/icons.lua12
-rw-r--r--filters/lib/common.lua30
-rw-r--r--filters/macros.lua72
-rw-r--r--filters/tables.lua5
6 files changed, 88 insertions, 55 deletions
diff --git a/filters/code.lua b/filters/code.lua
new file mode 100644
index 0000000..2d6e5a5
--- /dev/null
+++ b/filters/code.lua
@@ -0,0 +1,15 @@
1local common = require 'filters.lib.common'
2
3function CodeBlock(el)
4 if el.classes[1] == "plain" then
5 el = pandoc.Div({ el }, { class = 's-code' })
6 elseif el.classes[1] then
7 local formatted = pandoc.pipe('pygmentize', {
8 '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight',
9 }, el.text)
10
11 if formatted then el = pandoc.RawBlock('html', formatted) end
12 end
13
14 return common.wide(el)
15end
diff --git a/filters/headers.lua b/filters/headers.lua
new file mode 100644
index 0000000..ea9cde6
--- /dev/null
+++ b/filters/headers.lua
@@ -0,0 +1,9 @@
1function Header(el)
2 if el.level <= 3 then
3 local newchildren = pandoc.List()
4 newchildren:insert(pandoc.Span(el.content, { class = 's-headings__primary' }))
5 el.content = newchildren
6 end
7
8 return el
9end
diff --git a/filters/icons.lua b/filters/icons.lua
new file mode 100644
index 0000000..9e921f3
--- /dev/null
+++ b/filters/icons.lua
@@ -0,0 +1,12 @@
1function Str(el)
2 local icon = el.text:match('^:(.*):$')
3
4 if icon then
5 return pandoc.RawInline('html',
6 '<svg class="o-icon o-icon--inline" width="1em" height="1em" aria-hidden="true">\
7 <use href="/icons.svg#' .. icon .. '"></use>\
8 </svg>')
9 end
10
11 return el
12end
diff --git a/filters/lib/common.lua b/filters/lib/common.lua
new file mode 100644
index 0000000..7654eb9
--- /dev/null
+++ b/filters/lib/common.lua
@@ -0,0 +1,30 @@
1function wide(el)
2 local els = pandoc.List()
3
4 els:insert(pandoc.RawBlock("html", "</div>"))
5 if pcall(function() return #el end) then
6 els:extend(el)
7 else
8 els:insert(el)
9 end
10 els:insert(pandoc.RawBlock("html", "<div class=\"l-container l-container--narrow u-ml-0\">"))
11
12 return els
13end
14
15function dump(o)
16 if type(o) == 'table' then
17 local s = '{ '
18 for k, v in pairs(o) do
19 if type(k) ~= 'number' then k = '"' .. k .. '"' end
20 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
21 end
22 return s .. '} '
23 else
24 return tostring(o)
25 end
26end
27
28return {
29 wide = wide
30}
diff --git a/filters/macros.lua b/filters/macros.lua
index cb7975b..04cead6 100644
--- a/filters/macros.lua
+++ b/filters/macros.lua
@@ -1,12 +1,6 @@
1function wide(el) 1local common = require 'filters.lib.common'
2 local els = pandoc.List()
3 2
4 els:insert(pandoc.RawBlock("html", "</div>")) 3local vars = {}
5 els:insert(el)
6 els:insert(pandoc.RawBlock("html", "<div class=\"l-container l-container--narrow u-ml-0\">"))
7
8 return els
9end
10 4
11function alert(el) 5function alert(el)
12 el.classes = pandoc.List() 6 el.classes = pandoc.List()
@@ -14,22 +8,26 @@ function alert(el)
14 el.classes:insert("o-alert--primary") 8 el.classes:insert("o-alert--primary")
15 el.classes:insert("s-alerts__alert") 9 el.classes:insert("s-alerts__alert")
16 10
17 return wide(el) 11 return common.wide(el)
18end 12end
19 13
20function figure(el) 14function figure(el)
21 local images = pandoc.List() 15 local images = pandoc.List()
22
23 pandoc.walk_block(el, { Image = function(iel) images:insert(iel) end }) 16 pandoc.walk_block(el, { Image = function(iel) images:insert(iel) end })
17 images[1].classes:insert("c-figure__image")
18
19 local class = "c-figure js-lightbox__image"
20 if vars.layout and vars.layout.is_exhibit then
21 class = class .. " u-d-none@js"
22 end
23
24 el = pandoc.List()
24 25
25 el = pandoc.RawBlock("html", 26 el:insert(pandoc.RawBlock("html", "<figure class=\"" .. class .. "\">"))
26 "<figure class=\"c-figure js-lightbox__image\">\ 27 el:insert(pandoc.Link(images[1], images[1].src, nil, { class = "c-figure__link" }))
27 <a class=\"c-figure__link\" href=\"" .. images[1].src .. "\">\ 28 el:insert(pandoc.RawBlock("html", "</figure>"))
28 <img class=\"c-figure__image\" src=\"" .. images[1].src .. "\" title=\"" .. images[1].title .. "\" />\
29 </a>\
30 </figure>")
31 29
32 return wide(el) 30 return common.wide(el)
33end 31end
34 32
35function Div(el) 33function Div(el)
@@ -42,42 +40,6 @@ function Div(el)
42 return el 40 return el
43end 41end
44 42
45function CodeBlock(el) 43function meta(meta) vars = meta end
46 if el.classes[1] == "plain" then
47 el = pandoc.Div({ el }, { class = 's-code' })
48 elseif el.classes[1] then
49 local formatted = pandoc.pipe('pygmentize', {
50 '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight',
51 }, el.text)
52
53 if formatted then el = pandoc.RawBlock('html', formatted) end
54 end
55
56 return wide(el)
57end
58
59function Header(el)
60 if el.level <= 3 then
61 local newchildren = pandoc.List()
62 newchildren:insert(pandoc.Span(el.content, { class = 's-headings__primary' }))
63 el.content = newchildren
64 end
65
66 return el
67end
68
69function Table(el)
70 return wide(el)
71end
72 44
73function Str(el) 45return { { Meta = meta }, { Div = Div } }
74 local icon = el.text:match('^:(.*):$')
75
76 if icon then
77 return pandoc.RawInline('html',
78 '<svg class="o-icon o-icon--inline" width="1em" height="1em" aria-hidden="true"><use href="/icons.svg#' ..
79 icon .. '"></use></svg>')
80 end
81
82 return el
83end
diff --git a/filters/tables.lua b/filters/tables.lua
new file mode 100644
index 0000000..2ff4eea
--- /dev/null
+++ b/filters/tables.lua
@@ -0,0 +1,5 @@
1local common = require 'filters.lib.common'
2
3function Table(el)
4 return common.wide(el)
5end