Skip to content

Commit

Permalink
Makefile: add pandoc lua script to verify section links
Browse files Browse the repository at this point in the history
Closes #402
  • Loading branch information
sluicing authored and bagder committed Jan 6, 2024
1 parent f2c122a commit e523eb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ uni.md: uni.pl $(MDS) SUMMARY.md $(OUT)
./uni.pl SUMMARY.md >$@

everything-curl.html: uni.md $(MDS)
pandoc -o everything-curl.html uni.md
pandoc --lua-filter=warn_bad_links.lua -o everything-curl.html uni.md
rm -rf everything-curl
mkdir -p everything-curl
cp -p `grep -oe 'img src="[0-9a-z/.-]*' everything-curl.html | cut -c10-` everything-curl/
Expand All @@ -34,12 +34,12 @@ everything-curl.html: uni.md $(MDS)
html: everything-curl.html

everything-curl.pdf: uni.md
pandoc -o everything-curl.pdf pdf.txt uni.md --toc
pandoc --lua-filter=warn_bad_links.lua -o everything-curl.pdf pdf.txt uni.md --toc

pdf: everything-curl.pdf

everything-curl.epub: uni.md
pandoc -o everything-curl.epub --epub-cover-image=cover.jpg epub.txt uni.md
pandoc --lua-filter=warn_bad_links.lua -o everything-curl.epub --epub-cover-image=cover.jpg epub.txt uni.md

epub: everything-curl.epub

Expand Down
27 changes: 27 additions & 0 deletions warn_bad_links.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- I recently used a Lua filter for this purpose. It worked quite well:

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}
}

0 comments on commit e523eb8

Please sign in to comment.