2024-05-16 23:13:00 +02:00
|
|
|
-- local l = require("pandoc.logging")
|
|
|
|
local read = pandoc.read
|
|
|
|
|
|
|
|
assert(#arg == 1, "\n" ..
|
|
|
|
"[ERROR] usage: pandoc lua collect_links.lua <file>...")
|
|
|
|
|
|
|
|
local f = assert(io.open(arg[1]), "\n" ..
|
|
|
|
"[ERROR] could not open " .. arg[1] .. " for reading.")
|
|
|
|
|
|
|
|
local data = f:read("a")
|
|
|
|
f:close()
|
|
|
|
local visited = {}
|
|
|
|
read(data):walk({ Link = function (link)
|
2024-05-17 15:26:37 +02:00
|
|
|
if not link.target:find(".%.md$") then return end
|
2024-05-16 23:13:00 +02:00
|
|
|
local f = io.open(link.target)
|
|
|
|
if f == nil then return else f:close() end
|
|
|
|
if visited[link.target] then return end
|
|
|
|
visited[link.target] = true
|
|
|
|
io.write(link.target .. "\n")
|
|
|
|
end })
|