---@diagnostic disable: undefined-global
-- see https://pandoc.org/lua-filters.html
return {
Link = function(link)
-- set target="_blank" for outgoing links (open them in new tab)
if string.match(link.target, "gzr.im") == nil then
table.insert(link.attributes, { "target", "_blank" })
end
return link
end,
Pandoc = function(doc)
local front = pandoc.List()
local doc_filename = pandoc.path.filename(PANDOC_STATE.input_files[1])
-- add a comment
front:extend({
pandoc.RawBlock("html5", ""),
})
local toc = pandoc.structure.table_of_contents(doc)
if doc.meta.toc and toc then
front:extend({
pandoc.RawBlock("html5", '"),
})
end
-- insert date blocks
if doc.meta.date then
front:extend({
pandoc.RawBlock("html5", ''),
doc.meta.date,
pandoc.RawBlock("html5", ""),
})
end
-- prepend front stuffs
front:extend(doc.blocks)
doc.blocks = front
-- return finished ast
return doc
end,
}