From a43ca52aa2d102c7499c7fd8478304a26ea2cd0a Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 18 Jun 2022 15:51:18 +0200 Subject: Improved Lua filters, improved exhibit pages --- filters/code.lua | 15 +++++++++++ filters/headers.lua | 9 +++++++ filters/icons.lua | 12 +++++++++ filters/lib/common.lua | 30 +++++++++++++++++++++ filters/macros.lua | 72 ++++++++++++-------------------------------------- filters/tables.lua | 5 ++++ 6 files changed, 88 insertions(+), 55 deletions(-) create mode 100644 filters/code.lua create mode 100644 filters/headers.lua create mode 100644 filters/icons.lua create mode 100644 filters/lib/common.lua create mode 100644 filters/tables.lua (limited to 'filters') 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 @@ +local common = require 'filters.lib.common' + +function CodeBlock(el) + if el.classes[1] == "plain" then + el = pandoc.Div({ el }, { class = 's-code' }) + elseif el.classes[1] then + local formatted = pandoc.pipe('pygmentize', { + '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight', + }, el.text) + + if formatted then el = pandoc.RawBlock('html', formatted) end + end + + return common.wide(el) +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 @@ +function Header(el) + if el.level <= 3 then + local newchildren = pandoc.List() + newchildren:insert(pandoc.Span(el.content, { class = 's-headings__primary' })) + el.content = newchildren + end + + return el +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 @@ +function Str(el) + local icon = el.text:match('^:(.*):$') + + if icon then + return pandoc.RawInline('html', + '') + end + + return el +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 @@ +function wide(el) + local els = pandoc.List() + + els:insert(pandoc.RawBlock("html", "")) + if pcall(function() return #el end) then + els:extend(el) + else + els:insert(el) + end + els:insert(pandoc.RawBlock("html", "
")) + + return els +end + +function dump(o) + if type(o) == 'table' then + local s = '{ ' + for k, v in pairs(o) do + if type(k) ~= 'number' then k = '"' .. k .. '"' end + s = s .. '[' .. k .. '] = ' .. dump(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + +return { + wide = wide +} 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 @@ -function wide(el) - local els = pandoc.List() +local common = require 'filters.lib.common' - els:insert(pandoc.RawBlock("html", "
")) - els:insert(el) - els:insert(pandoc.RawBlock("html", "
")) - - return els -end +local vars = {} function alert(el) el.classes = pandoc.List() @@ -14,22 +8,26 @@ function alert(el) el.classes:insert("o-alert--primary") el.classes:insert("s-alerts__alert") - return wide(el) + return common.wide(el) end function figure(el) local images = pandoc.List() - pandoc.walk_block(el, { Image = function(iel) images:insert(iel) end }) + images[1].classes:insert("c-figure__image") + + local class = "c-figure js-lightbox__image" + if vars.layout and vars.layout.is_exhibit then + class = class .. " u-d-none@js" + end + + el = pandoc.List() - el = pandoc.RawBlock("html", - "
\ - \ - \ - \ -
") + el:insert(pandoc.RawBlock("html", "
")) + el:insert(pandoc.Link(images[1], images[1].src, nil, { class = "c-figure__link" })) + el:insert(pandoc.RawBlock("html", "
")) - return wide(el) + return common.wide(el) end function Div(el) @@ -42,42 +40,6 @@ function Div(el) return el end -function CodeBlock(el) - if el.classes[1] == "plain" then - el = pandoc.Div({ el }, { class = 's-code' }) - elseif el.classes[1] then - local formatted = pandoc.pipe('pygmentize', { - '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight', - }, el.text) - - if formatted then el = pandoc.RawBlock('html', formatted) end - end - - return wide(el) -end - -function Header(el) - if el.level <= 3 then - local newchildren = pandoc.List() - newchildren:insert(pandoc.Span(el.content, { class = 's-headings__primary' })) - el.content = newchildren - end - - return el -end - -function Table(el) - return wide(el) -end +function meta(meta) vars = meta end -function Str(el) - local icon = el.text:match('^:(.*):$') - - if icon then - return pandoc.RawInline('html', - '') - end - - return el -end +return { { Meta = meta }, { Div = Div } } 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 @@ +local common = require 'filters.lib.common' + +function Table(el) + return common.wide(el) +end -- cgit v1.2.3-70-g09d2