Convert Markdown to HTML in Command-line

In this article, I have covered how to convert Markdown to HTML in command-line using Node.js command.

Table of Contents

Introduction

Converting Markdown to HTML in the command-line is a frequent task for developers and content creators. The NPM package Showdown is a robust tool that makes this process straightforward. This tutorial will guide you through the steps of installing and using Showdown to convert Markdown to HTML directly from your command-line environment.

Markdown to HTML in command-line

Installation Steps

First, ensure that Node.js and npm (Node Package Manager) are installed on your machine. Then run the following command to install Showdown:

npm install -g showdown

This will install Showdown globally on your system, allowing you to use it in any directory via the command-line.

Basic Usage

To convert a Markdown file to HTML using Showdown, use the following command:

showdown makehtml -i input.md -o output.html
  • makehtml: This is a subcommand of Showdown used to specify that you want to convert Markdown to HTML.
  • -i input.md: This part of the command specifies the input file (-i stands for input). In this example, it’s set to input.md, which is assumed to be your Markdown file. You can replace input.md with the actual path or filename of your Markdown file.
  • -o output.html: This part of the command specifies the output file (-o stands for output). In this example, it’s set to output.html, which is assumed to be the desired name for your HTML file. You can replace output.html with the desired path or filename for your HTML output.

Replace input.md with your markdown file and output.html with the desired output HTML file name.

Using Options

Showdown provides various options to customize the conversion process. For instance, to enable GitHub flavored markdown, use the --flavor option:

showdown makehtml --flavor github -i input.md -o output.html

Visit the Showdown GitHub repository to see a full list of options available for customization.

 

To enable the conversion of tables and strikethrough text

showdown makehtml -i example.md -o example.html --tables --strikethrough

 

Citations and References

Conclusive Summary

In a nutshell, turning your Markdown into HTML through the command line is super easy with the Showdown npm package. This guide walked you through installing Showdown, using it for basic conversion, tweaking the process with options, and even adding plugins. With the help of simple examples, you should now feel comfortable transforming your Markdown files into HTML effortlessly.