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.
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.
If I recall, “line after line of regular expressions” is one of the things Perl is designed for. So not really ‘dark magic’.
If you like cli syntax highlighting, checkout ‘bat’. A bit like cat on steroids.
https://github.com/sharkdp/bat
Ow, bat is nice, thanks for the tip.
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
Oh, my initial “bash vs Perl” comment got removed. I hope it was because of incorrect grammar.
[Insert “first time?” meme here]
Poor Perl, doing all the heavy lifting while Bash gets all the praise.
But one of the points of Markdown is that it doesn’t require a renderer at all… it should look nice by default…
Interesting… I fancy a port from perl to awk. 😎
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. =)
I like more mdless, it has color and a more familiar usage
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.