Add internal link checker

This should make the link rewriting process easier. As this does
the same job as epubChecker, it can probably be removed once
epubChecker is integrated into the build process.
This commit is contained in:
Michael Reed 2020-06-15 14:24:29 -04:00
parent 02bf885d6b
commit dbed30c659
2 changed files with 28 additions and 0 deletions

View file

@ -59,6 +59,7 @@ out/plfa.epub: out/ $(AGDA) $(LUA) epub.css fonts/*.ttf
--css=epub.css \
--epub-embed-font='fonts/*.ttf' \
--lua-filter include-files.lua \
--lua-filter check-internal-links.lua \
--lua-filter default-code-class.lua -M default-code-class=agda \
--standalone \
--toc --toc-depth=2 \

27
check-internal-links.lua Normal file
View file

@ -0,0 +1,27 @@
-- Source: https://github.com/jgm/pandoc/issues/1621#issuecomment-613336520
local identifiers = {}
function Block (b)
if b.identifier then
identifiers[b.identifier] = true
end
end
function Inline (i)
if i.identifier then
identifiers[i.identifier] = true
end
end
function Link (l)
local anchor = l.target:match('#(.*)')
if anchor and not identifiers[anchor] then
io.stderr:write("broken link: " .. anchor .. "\n")
end
end
return {
{Block = Block, Inline = Inline},
{Link = Link}
}