Convert Markdown to HTML

I’m making a macro where one step is to get the Markdown contents from the clipboard (or the currently open text file but I can figure that out) and pass it on as HTML to the next step in the macro. I’m searching this forum and also googling for this but I cannot find a solution for this. Does anyone know a simple way to do this within KM?

You’ll need a shell script to convert Markdown to HTML (I imagine they are easy to find on the net).

Then you use execute script with an Execute Shell Script action, and have it just read directly from the clipboard using the pbpaste tool:

pbpaste | ~/Wherever/MyMarkDownConverter

The results of the Execute Shell Script ate then put into the Clipboard or Variable or whatever.

Pandoc is pretty good with Markdown and very flexible. So, once Pandoc is installed, you can do something like this:

[demo] Markdown Clipboard to HTML.kmmacros (2.7 KB)

Since there are about a dozen different Markdown flavors around, you want to set the correct flavor in order to meet your input (except you have a very basic Markdown with only * tags). See the excellent documentation for available input formats and other options.

PS: If you want to get the input from an open text document, just prepend a Keystroke-⌘A action and a Copy action.


Thanks! In the end I’ve used the markdown command line utility because pandoc gave me an error.