Files
readableFilter/filter.lua
2025-10-09 19:51:29 +08:00

21 lines
605 B
Lua

function File2Block(filename)
local fh = io.open(filename, "r")
if not fh then
io.stderr:write("Cannot open file: " .. filename .. "\n")
return { pandoc.Plain { pandoc.Str("[Error: cannot read file " .. filename .. "]") } }
end
local contents = fh:read("*a")
fh:close()
return { pandoc.Plain { pandoc.Str(contents) } }
end
function Div(e)
local include = e.attributes["include"]
if include then
local blocks = File2Block(include)
-- Replace the Div contents
return pandoc.Div(blocks, e.attr)
end
return nil -- no change
end