4 Markdown Utilities for the Linux Command Line

(Note: This article was first published, in a slightly different form, at Opensource.com and appears here via a CC BY-SA 4.0 license.)

When it comes to working with files formatted with Markdown, tools at the command line rule the roost. They’re light, fast, powerful, and flexible. Most of them follow the UNIX philosophy of doing one thing well.

Let’s take a look at four utilities that can help you work more efficiently with Markdown files at the command line.

mdless

If you’ve hung around the Linux command line for a while, you’re probably familiar with a text file viewer called less. Sure, you can use less to view Markdown files but the result is a tad dull. How can you view Markdown files with a bit of pizzazz in a terminal window? By using mdless.

Viewing a file with mdless

You can move around using the arrow keys on your keyboard, and mdless packs quite a good search function.

Not only does mdless display text, it renders formatting like headings, bold, and italics. It can also display tables and do syntax highlighting of code blocks. You can also customize the look and feel of mdless by creating one or more theme files.

Markdown lint tool

When you’re typing quickly, you make mistakes. If you miss a bit of formatting when using Markdown (or any other markup language), that can cause problems when you convert your file to another format.

Coders often use tools called linters to check for correct syntax. You can do the same for Markdown using the Markdown lint tool.

When you run this tool over a file that’s formatted with Markdown, it check the formatting against a set of rules. Those rule govern the structure of a document including the order of header levels, incorrect indentation and spacing, problems with code block, the existence of HTML in a file, and more.

Finding problems with a Markdown file using the Markdown lint tool

The rules can be a bit strict. But running Markdown lint tool over a file before converting it to another format can prevent the grief that comes from bad or inconsistent formatting.

mdmerge

Combining files of any kind can be a pain. Take, for example, an ebook that I published in early 2020. It’s a collection of essays that first appeared in my weekly email letter. Those essays were in individual files, and being the masochist that I am, I combined them in a messy, manual way.

I wish I’d known about mdmerge before I started that project. It would have saved me a lot of time and energy.

mdmerge, as you’ve probably guessed from its name, combines two or more Markdown files into a single file. You don’t need to type the names of the files at the command line. Instead, you can add them to a file called book.txt and then use that as an input file for mdmerge.

That’s not all mdmerge can do. You can add a reference to another document — either one formatted with Markdown or a piece of source code — and pull it into your main document. That enables you to create master documents that you can tailor to specific audiences.

mdmerge isn’t one of those utilities that you’ll use all the time. When you need it, you’ll be glad it’s on your hard drive.

bashblog

bashblog isn’t strictly a tool for working with Markdown. It takes files that are formatted using Markdown and uses them to build a simple blog or website. Think of bashblog as a static site generator, but one that doesn’t have a bunch of fragile dependencies. Just about everything you need is in a shell script weighing in at just under 50 KB.

To use bashblog, all you need is a Markdown processor installed on your computer. From there, you edit the shell script to add information about your blog — for example, its title, your name, your social media links, and the like. Then run the script. A new post opens in your default text editor. Start typing.

After you save a post, you can publish it or save it as a draft. If you choose to publish the post, bashblog generates your blog, posts and all, as a set of HTML files that you can upload to a web server.

Out of the box, your blog is bland but serviceable. You can edit the blog’s CSS file, or drop in one of your own, to give it a unique look and feel.

An out-of-the-box blog created with bashblog

(Note: I’ll be taking a closer look at bashblog in a future article.)

What about Pandoc?

No, I didn't miss or forget Pandoc. It's a deliberate omission. Sure, Pandoc is a very powerful tool for converting files formatted with Markdown to other markup languages. But, believe it or not, there’s more to working with Markdown at the command line than Pandoc.