clean-up
parent
7f283451b5
commit
54c4f5c9bf
|
@ -1,51 +0,0 @@
|
|||
local l = require("pandoc.logging")
|
||||
assert(#arg > 0, "\n" ..
|
||||
"[ERROR] usage: pandoc lua dependencies.lua <input-file>")
|
||||
|
||||
for i, v in ipairs(arg) do
|
||||
local f = assert(io.open(v), "\n" ..
|
||||
"[ERROR] could not open " .. v .. " for reading.")
|
||||
local data = f:read("a")
|
||||
f:close()
|
||||
|
||||
local visited = {}
|
||||
pandoc.read(data):walk({ Link = function(link)
|
||||
-- early return for external links
|
||||
if link.target:find("^https?%:%/%/") then return end
|
||||
if link.target:find("^mailto%:") then return end
|
||||
|
||||
local fp, anchor = link.target:match("^(.+%.md)#?(.*)$")
|
||||
-- early return for non markdown files
|
||||
if not fp then return end
|
||||
|
||||
local f = io.open(fp)
|
||||
if f == nil then
|
||||
print("Broken internal link: " .. v .. " -> " .. fp)
|
||||
return
|
||||
end
|
||||
|
||||
if anchor == "" then f:close(); return end
|
||||
|
||||
local data = f:read("a"); f:close()
|
||||
|
||||
local found = false
|
||||
pandoc.read(data):walk({ Div = function(div)
|
||||
if not div.attr then return end
|
||||
if div.attr.identifier == anchor then found = true end
|
||||
end }):walk({ Span = function(span)
|
||||
if not span.attr then return end
|
||||
if span.attr.identifier == anchor then found = true end
|
||||
end }):walk({ Header = function(header)
|
||||
if not header.attr then return end
|
||||
if header.attr.identifier == anchor then found = true end
|
||||
end }):walk({ CodeBlock = function(codeblock)
|
||||
if not codeblock.attr then return end
|
||||
if codeblock.attr.identifier == anchor then found = true end
|
||||
end }):walk({ Code = function(code)
|
||||
if not code.attr then return end
|
||||
if code.attr.identifier == anchor then found = true end
|
||||
end })
|
||||
|
||||
if not found then print("Broken link: " .. v .. " -> " .. link.target) end
|
||||
end })
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
assert(#arg == 1, "\n" ..
|
||||
"[ERROR] usage: pandoc lua dependencies.lua <input-file>")
|
||||
local input_file = arg[1]
|
||||
|
||||
local f = assert(io.open(input_file), "\n" ..
|
||||
"[ERROR] could not open " .. input_file .. " for reading.")
|
||||
local data = f:read("a")
|
||||
f:close()
|
||||
|
||||
local base, _ = pandoc.path.split_extension(input_file)
|
||||
io.write(("public_html/%s.html:"):format(base))
|
||||
|
||||
local prerequisites = {}
|
||||
|
||||
pandoc.read(data):walk({ Link = function(link)
|
||||
-- early return for external links
|
||||
if link.target:find("^https?%:%/%/") then return end
|
||||
if link.target:find("^mailto%:") then return end
|
||||
|
||||
local fp, anchor = link.target:match("^(.+%.md)#?(.*)$")
|
||||
-- early return for non markdown files
|
||||
if not fp then return end
|
||||
|
||||
local f = io.open(fp)
|
||||
-- early return for broken internal links
|
||||
if f == nil then return else f:close() end
|
||||
|
||||
-- early return for already collected
|
||||
if prerequisites[fp] then return end
|
||||
prerequisites[fp] = true
|
||||
|
||||
local base, _ = pandoc.path.split_extension(fp)
|
||||
io.write(" ", ("public_html/%s.html.part"):format(base))
|
||||
end })
|
Loading…
Reference in New Issue