Many times, when I use Markdown, I work on one file and when I’m done with it, I convert it to HTML or some other format. Occasionally, I have to create a few files. When I do work with more than one Markdown file, I usually wait until I have finished them before I convert them.

I use pandoc to convert files, and it’s possible convert all the Markdown files in one shot.

Markdown can convert its files to .html, but if there’s a chance that I will have to convert to other formats like epub, pandoc is the tool to use. I prefer to use the command line, so I will cover that first, but you can also do this in VSCodium without the command line. I’ll cover that too.

Converting multiple Markdown files to another format with Pandoc [command line method]

To get started quickly, Ubuntu, and other Debian distros can type the following commands in the terminal:

sudo apt-get install pandoc

In this example, I have four Markdown files in a directory called md_test.

bdyer@bill-pc:~/Documents/md_test$ ls -l *.md
-rw-r--r-- 1 bdyer bdyer 3374 Apr 7 2020 file01.md
-rw-r--r-- 1 bdyer bdyer 782 Apr 2 05:23 file02.md
-rw-r--r-- 1 bdyer bdyer 9257 Apr 2 05:21 file03.md
-rw-r--r-- 1 bdyer bdyer 9442 Apr 2 05:21 file04.md
bdyer@bill-pc:~/Documents/md_test$

There are no HTML files yet. Now I’ll use Pandoc to do its magic on the collection of files. To do this, I run a one-line command that:

  • calls pandoc
  • reads the .md files and exports them as .html

This is the command:

for i in *.md ; do echo "$i" && pandoc -s $i -o $i.html ; done

If you are not aware already, ; is used for running multiple commands at once in Linux.

Here’s what the display looks like once I have executed the command:

bdyer@bill-pc:~/Documents/md_test$ for i in *.md ; do echo "$i" && pandoc -s $i -o $i.html ; done
file01.md
file02.md
file03.md
file04.md
bdyer@bill-pc:~/Documents/md_test$

Let me use the ls command once more to see if HTML files were created:

bdyer@bill-pc:~/Documents/md_test$ ls -l *.html
-rw-r--r-- 1 bdyer bdyer 4291 Apr 2 06:08 file01.md.html
-rw-r--r-- 1 bdyer bdyer 1781 Apr 2 06:08 file02.md.html
-rw-r--r-- 1 bdyer bdyer 10272 Apr 2 06:08 file03.md.html
-rw-r--r-- 1 bdyer bdyer 10502 Apr 2 06:08 file04.md.html
bdyer@bill-pc:~/Documents/md_test$

The conversion was a success, and you have four HTML files ready to go on the Web server.

Pandoc is quite versatile and you can convert the markdown files to some other supported format by specifying the extension of the output files. You can understand why it is considered among the best open source tools for writers.

.ugb-a4f08a0-wrapper.ugb-container__wrapper{border-radius:0px !important;padding-top:0 !important;padding-bottom:0 !important;background-color:#f1f1f1 !important}.ugb-a4f08a0-wrapper > .ugb-container__side{padding-top:35px !important;padding-bottom:35px !important}.ugb-a4f08a0-wrapper.ugb-container__wrapper:before{background-color:#f1f1f1 !important}.ugb-a4f08a0-content-wrapper > h1,.ugb-a4f08a0-content-wrapper > h2,.ugb-a4f08a0-content-wrapper > h3,.ugb-a4f08a0-content-wrapper > h4,.ugb-a4f08a0-content-wrapper > h5,.ugb-a4f08a0-content-wrapper > h6{color:#222222}.ugb-a4f08a0-content-wrapper > p,.ugb-a4f08a0-content-wrapper > ol li,.ugb-a4f08a0-content-wrapper > ul li{color:#222222}

Recommended Read:

.ugb-921b5c0 .ugb-blog-posts__featured-image{border-radius:0px !important}.ugb-921b5c0 .ugb-blog-posts__title a{color:#000000 !important}.ugb-921b5c0 .ugb-blog-posts__title a:hover{color:#00b6ba !important}

11 Best Markdown Editors for Linux

11 Best Markdown Editors for Linux

A list of best Markdown Editors for Linux distributions that not only look good but are also feature rich.