How to open formatted markdown files in Linux terminal

Markdown files (.md) are extensively used in Github and other places for various purposes. No doubt that they are getting more and more popular. For instance, Leanpub supports markdown for writing books or better to be said it relies on markdown. Besides that many people use markdown for writing scientific papers instead of LaTeX since it is simpler to use.
Writing in markdown does not require any special tool, only requirement is a text editor. However, in order to see the output of markdown files, you are either need to install some applications or rely on online tools.
This can be quite a bit of hassle especially for those who prefer Linux command line. Fortunately, there are some tools (but not perfect) available for that. Among all Pandoc seems to be the best option.
You just simply need to install it and then run it to get the output of the markdown in HTML format.
To install it in Ubuntu, you need to use apt-get command like this,

$ sudo apt-get install pandoc

To convert markdown files to HTML use pandoc as follows:

$ pandoc foo.md > bar.html

The generated HTML file is viewable in any text-based browser such as Lynx.
To make the process even simpler, we can eliminate saving HTML file by pipelining the output of the pandoc directly to Lynx like this.

$ pandoc foo.md | lynx -stdin

Leave a Reply