Thursday, October 15, 2015

Markdown editing and live preview with three simple tools.

Here's a simple way to edit and preview a text markup language without a special-purpose editor. In this case we will be editing markdown in a Linux machine and preview the result almost instantly.


Here's the setup:
  • The markdown is changed with a text editor (it does not matter which one) which saves it,
  • The program when-changed notices the change and runs pandoc,
  • pandoc generates an HTML file from the markdown,
  • Firefox is continually open and is displaying the HTML file from the hard drive, and
  • the Firefox 'Auto Reload' plug notices the HTML was changed and redisplays it.
All you need to do is place the Firefox window beside the editor window and you have live updates! And this will also work for any other text-based markup tools which render to HTML...

Some Technical details:
  • Centos 6.6
  • python 2.6
  • when-changed (0.2.1) ($ pip install when-changed)
  • Firefox 31.6.0
  • Auto Reload 1.2.0
Command-line for when-changed:
when-changed mymarkdown.md pandoc --from=markdown --to=html --output=mymarkdown.md.html mymarkdown.md

No comments: