Preview Markdown In The Terminal With Bash

Markdown has become an extremely popular way to document source code and other projects, thanks in no small part to how well web-based services like GitHub render it. Just sprinkle a few extra characters into a regular text file, and all of a sudden it looks like you know what you’re doing. Unfortunately, there are some places where markdown won’t actually render, and you’ll be stuck looking at those extra characters.

But thanks to MarCLIdown, the terminal doesn’t have to be one of those places. Written by [NihaAlGhul], this simple tool takes a given markdown file and spits out a fairly impressive rendering — and you don’t even need to have one of those fancy new GPU-accelerated terminals. Most impressively, the whole thing is implemented as a single Bash script.

How does it work? Some would say it’s magic. Others would point out the inline Perl, conditionals statements, and line after line of regular expressions. Ultimately, we’d argue they’re the same thing.

Definitely Dark Magic

As you can probably imagine not everything is supported by MarCLIdown, but the list of what’s currently working is already quite impressive. Headers, check boxes, lists, block quotes, links, all work and look pretty much as you’d expect. The biggest omission at this point is probably tables, but even that isn’t really a deal breaker.

MarCLIdown isn’t the first tool to try and visualize markdown in the terminal. Readers may already be familiar with glow, which is more mature and admittedly has the edge in terms of capability. But the fact that [NihaAlGhul] managed to get this far with just a single Bash script is a proper hack, and one we think worthy of some special consideration.

12 thoughts on “Preview Markdown In The Terminal With Bash

      1. This script is very cool. We need to remember there is no such thing as “The Terminal”, but many terminal emulators. Some can print text in bold, italics, color and even images (ie sixel), others cannot. We can view markdown (with images) by converting the code to HTML with Pandoc and viewing the result with a browser like w3m. Basically it’s a parsing job. In theory you probably could do a similar thing using sed, awk and tput. Using a terminal you can also produce LaTeX documents, convert them into PDF and view the result using tools like fbgs or fbi. All without using X and using the framebuffer instead.

  1. Original Markdown was a very hacky Perl script, so the whole thing is based on chaotic black magic.

    These days I prefer LaTeX for things that have to look nice. Markdown is cool to take a quick note, though — it even works on paper. =)

  2. This script is very cool. We need to remember there is no such thing as “The Terminal”, but many terminal emulators. Some can print text in bold, italics, color and even images (ie sixel), others cannot. We can view markdown (with images) by converting the code to HTML with Pandoc and viewing the result with a browser like w3m. Basically it’s a parsing job. In theory you probably could do a similar thing using sed, awk and tput. Using a terminal you can also produce LaTeX documents, convert them into PDF and view the result using tools like fbgs or fbi. All without using X and using the framebuffer instead.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.