Markdown Previews

Say you want to edit in your favorite text editor but want to see a preview of the resulting HTML in Safari. On Mac OS X. Get yourself a new bash shell and run the following commands:

brew install multimarkdown
brew install fswatch

echo '#!/bin/bash
multimarkdown --full "" > \
/tmp/file.html && \
open -g /tmp/file.html' > /tmp/ \
&& chmod +x /tmp/; \
fswatch -o "" | xargs -n1 /tmp/

Now every time you save, fswatch will run the rebuild script, passing the file through multimarkdown and handing the resulting HTML file to the open command. The -g flag in open keeps Safari from jumping to the foreground every time the script runs.

Safari has the nice feature that if you click on a link to while is already loaded in some tab, it will switch to that tab and reload the page. Not sure if Chrome does the same, but there's probably a setting or extension for that.

Note that there's a newline after the first line in the string we're passing to echo.

Who needs a dedicated live previewing markdown editor, anyway?