The following uses Lua filters to fix your links. It assumes that links are written by prefixing them with the file in which the link is defined, for example [see here](some-other-file.md#topic)
. Some editors make it simple to switch to the respective file, so this can be an additional advantage.
When converting to multiple HTML files, all we need to do is replace the .md
file extension in these links with .html
.
-- fix-links-multiple-files.lua
function Link (link)
link.target = link.target:gsub('(.+)%.md%#(.+)', '%1.html#%2')
return link
end
Run it with
pandoc --lua-filter fix-links-multiple-files.lua file-1.md -o file-1.html
In the case of a single file, we can just drop the file part of the link:
-- fix-links-single-file.lua
function Link (link)
link.target = link.target:gsub('.+%.md%#(.+)', '#%1')
return link
end
Run with
pandoc --lua-filter fix-links-single-file.lua *.md -o outfile.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…