Reading Markdown files at the console using w3m via MIME

Given my long stint doing a lot of sysadmin type work, which saw me working across many machines, often of disparate types, I have tended to customize my environment very lightly.

Doing less of that and more of other things, I've really begun to add some dependencies to my environments.

One thing I've started using more and more is the following:

cp /etc/mime.types ~/.w3m/
echo 'text/markdown md' >> ~/.w3m/mime.types

cp /etc/mailcap ~/.w3m/
echo 'text/markdown; pandoc -o - %s -t html ; x-htmloutput' >> ~/.w3m/mailcap

Now w3m README.md Does The Right Thing

I don't care what anyone says about how Markdown is meant to be readable in plaintext.

I get it, it's not bad.

But if there's a URL in there, it doesn't matter how sparse the markup is, it's going to be awkward. Except for very short URLs, the URL plus markup will likely either scroll off the screen, which is not readable, or wrap oddly, which isn't a good representation of the formatting.

If you want to see it as plaintext, use your pager.

As to how I got here, I've been using pandoc to proof some Markdown files already, but I'd been using a cumbersome process:

pandoc -o test.html filename.md ; xdg-open test.html

Once I proofed the file, I'd delete test.html and move on. Some files, particularly those loading images, might still benefit from this treatment.

For simpler marked-up text, I figured I could pipe pandoc output to a pager, like less, directly. That's when I started searching for inspiration, and found this stackoverflow answer showing how to feed pandoc output into the man command

I had found that, then lost the reference (I think because of the node.js context of the question to which the answer was offered). Then I started thinking about using w3m to do the necessary and went to dig that reference up again (another reason to put it here, too, so I'm less likely to lose it again).

Additionally, this is a quick proof of the markup--is there a typo? Did I get the number of spaces right for that code block? What's more, any external links or internal relative links here to other Markdown documents will Just Work; and can be followed as a test when writing collections of related .md documents; or when trying to read a set of them, as when pulled from a repo, for instance.

In my case, what inspired this was my trying to read a local copy from one of my clones of the tmux-resurrect README file.

Particularly, I was looking to follow the internal link to the documentation for saving per-window shell history

Pages

Categories

Tags