Skip to content

Instantly share code, notes, and snippets.

@airbornelamb
Last active April 5, 2024 10:49
Show Gist options
  • Save airbornelamb/ee8d62e728c10debd44fc56dfc72558f to your computer and use it in GitHub Desktop.
Save airbornelamb/ee8d62e728c10debd44fc56dfc72558f to your computer and use it in GitHub Desktop.
Systematic way to convert multiple markdown files to html

obtained from atom/markdown-preview#289

Yep, have a look at http://pandoc.org/ or markdown-it https://github.com/markdown-it

It now depends, whether you want to merge the HTMl files or not:

# Single output files
for f in *.md ; do pandoc ${f} -f markdown -t html -s -o ${f}.html  ; done
# One output file
pandoc *.md -f markdown -t -s html -o merged.html

There are other ways to do it recursively according to https://stackoverflow.com/questions/26126362/converting-all-files-in-a-folder-to-md-using-pandoc-on-mac

You can run this in the parent directory in the terminal

find ./ -iname "*.md" -type f -exec sh -c 'pandoc "${0}" -o "${0%.md}.pdf"' {} \;
@paolobenve
Copy link

for f in *.md ; do pandoc ${f} -f markdown -t html -s -o ${f}.html ; done

Double quotes are missin on ${f}, they are needed in order to work with file names with spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment