You could use Lua filters to fix the links.
To replace the .md with an .html we use the gsub command from lua which uses pattern matching and replacement.
The pattern to match against is as follows: (.+)%.md(.*)
. This provides the option to either have #Topic
attached or not. For example, if you don't just concatenate, but rather use multiple files.
For single file just don't input the name of the document in the markdown.
The Lua for multiple files looks as follows:
-- 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, as stated above, 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
Thank to @tarleb for the answer before, it was really helpful