From 312015e8f74ca1738e7160e5d66cad9dcb07c6fd Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 29 Dec 2021 15:51:49 +0100 Subject: Initial gallery macro --- filters/macros.lua | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'filters') diff --git a/filters/macros.lua b/filters/macros.lua index 9e9d954..dc04cfd 100644 --- a/filters/macros.lua +++ b/filters/macros.lua @@ -1,7 +1,39 @@ +function note(el) + el.classes = pandoc.List() + el.classes:insert("c-note") + return el +end + +function gallery(el) + el.classes = pandoc.List() + el.classes:insert("c-gallery") + + local cur = pandoc.Div(pandoc.List(), { class = "c-gallery__current" }) + local imageList = pandoc.Div(pandoc.List(), { class = "c-gallery__items" }) + + pandoc.walk_block(el, { + Image = function(iel) + iel.classes = pandoc.List() + iel.classes:insert("c-gallery__img") + + local lel = pandoc.Link(iel, iel.src) + lel.classes = pandoc.List() + lel.classes:insert("c-gallery__item") + + imageList.content:insert(lel) + end, + }) + + el.content = { cur, imageList } + + return el +end + function Div(el) if el.classes:includes("note") then - el.classes = pandoc.List() - el.classes:insert("c-note") + el = note(el) + elseif el.classes:includes("gallery") then + el = gallery(el) end return el -- cgit v1.2.3-70-g09d2