Matthew Lincoln, PhD Cultural Heritage Data & Info Architecture

Pandoc and the clipboard in OS X Terminal

If you use Markdown with any frequency, you’ve likely heard of the command line utility Pandoc that does a fantastic job of translating between Markdown and a host of formats from HTML to MS Word to EPUB. There’s lots of plugins out there to fit Markdown and Pandoc into your favorite text editor, but it can be useful to have the tool ready at hand no matter what variety of apps you’re using.

I use this scrap of bash code to let me copy any snippet of Markdown to the OS X clipboard and “pipe” the copied text into Pandoc. Not too many tutorials on using the OS X clipboard and Terminal mention that you can pipe the output of that program right back into the clipboard in one go:

pbpaste | pandoc -f markdown -t html | pbcopy

To make it dead easy on yourself, add this snippet as an alias in your ~/.bash_profile like so:

alias md="pbpaste | pandoc -f markdown -t html | pbcopy; echo 'Conversion done.'"

So now I just need to type md to swap the Markdown in my clipboard for HTML, ready to be pasted down anywhere.


Comments are enabled via Hypothes.is


Cite this post:

Lincoln, Matthew D. "Pandoc and the clipboard in OS X Terminal." Matthew Lincoln, PhD (blog), 15 Sep 2013, https://matthewlincoln.net/2013/09/15/pandoc-and-the-clipboard-in-os-x-terminal.html.


Tagged in: Code