diff options
Diffstat (limited to 'filters')
-rw-r--r-- | filters/code.lua | 15 | ||||
-rw-r--r-- | filters/headers.lua | 9 | ||||
-rw-r--r-- | filters/icons.lua | 12 | ||||
-rw-r--r-- | filters/lib/common.lua | 30 | ||||
-rw-r--r-- | filters/macros.lua | 72 | ||||
-rw-r--r-- | filters/tables.lua | 5 |
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 @@ | |||
1 | local common = require 'filters.lib.common' | ||
2 | |||
3 | function 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) | ||
15 | end | ||
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 @@ | |||
1 | function 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 | ||
9 | end | ||
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 @@ | |||
1 | function 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 | ||
12 | end | ||
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 @@ | |||
1 | function 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 | ||
13 | end | ||
14 | |||
15 | function 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 | ||
26 | end | ||
27 | |||
28 | return { | ||
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 @@ | |||
1 | function wide(el) | 1 | local common = require 'filters.lib.common' |
2 | local els = pandoc.List() | ||
3 | 2 | ||
4 | els:insert(pandoc.RawBlock("html", "</div>")) | 3 | local 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 | ||
9 | end | ||
10 | 4 | ||
11 | function alert(el) | 5 | function 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) |
18 | end | 12 | end |
19 | 13 | ||
20 | function figure(el) | 14 | function 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) |
33 | end | 31 | end |
34 | 32 | ||
35 | function Div(el) | 33 | function Div(el) |
@@ -42,42 +40,6 @@ function Div(el) | |||
42 | return el | 40 | return el |
43 | end | 41 | end |
44 | 42 | ||
45 | function CodeBlock(el) | 43 | function 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) | ||
57 | end | ||
58 | |||
59 | function 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 | ||
67 | end | ||
68 | |||
69 | function Table(el) | ||
70 | return wide(el) | ||
71 | end | ||
72 | 44 | ||
73 | function Str(el) | 45 | return { { 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 | ||
83 | end | ||
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 @@ | |||
1 | local common = require 'filters.lib.common' | ||
2 | |||
3 | function Table(el) | ||
4 | return common.wide(el) | ||
5 | end | ||