add a lua version

This commit is contained in:
2025-10-09 19:51:29 +08:00
parent a6dc981e6b
commit a0aa9e611b
4 changed files with 37 additions and 14 deletions

20
filter.lua Normal file
View File

@@ -0,0 +1,20 @@
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