In my new project I have multiple markdown files which are linked to each other. These links refer to the original .md
files.
Example: File README.md
... 1. [Development documentation](Development.md) 1. [User documentation](Usage.md) ...
If I convert these files with Pandoc, e.g. to html files, all links are still pointing to the original .md
file. What I'm looking for is a way to convert also the link type, which means that output files should refer to the output file type such as HTML, PDF, TeX etc. Is there a way to convert the internal link type with Pandoc?
I use this to convert the files:
pandoc -f markdown -t html5 input.md -o output.html
To convert Markdown to HTML using Typora, click File —> Export —> HTML.
You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.
There are actually two steps involved in converting a Markdown file to a PDF file: The Markdown source file is converted to a LaTeX source file. Pandoc invokes the pdflatex or xelatex or other TeX command and converts the . tex source file to a PDF file.
Example with the built-in Lua filters:
# links-to-html.lua function Link(el) el.target = string.gsub(el.target, "%.md", ".html") return el end
Then:
pandoc -f markdown -t html5 input.md -o output.html --lua-filter=links-to-html.lua
You can create a filter that checks every link element and--if the url ends with .md
--replaces it with .html
.
Example with Python, using the panflute package:
import panflute as pf def action(elem, doc): if isinstance(elem, pf.Link) and elem.url.endswith('.md'): elem.url = elem.url[:-3] + '.html' return elem if __name__ == '__main__': pf.run_filter(action)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With