summaryrefslogtreecommitdiffstats
path: root/filters/macros.lua
diff options
context:
space:
mode:
Diffstat (limited to 'filters/macros.lua')
-rw-r--r--filters/macros.lua72
1 files changed, 17 insertions, 55 deletions
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