pandoc & livereload on Windows

Thursday January 3, 2019

I tried to replicate this success on my Windowns 10 ultrabook, but I did not have much luck. entr tool does not exist for Windows, neiter does inotify-tools. I tried Facebook’s watchman, but I could not get it to work. Then I tried nodemon, it kinda worked but with some quirks. The browser-sync also failed to work properly. I set the port at 9000, but it defaulted to port 3000.

Hence, this called for a different approach. This solution is sort of hack-y, crafted during a short afternoon when I was doing my Western blot. I am currently using the while loop indefinitly to generate HTML5 document from markdown, and using python livereload server for hot-reloading the HTML output.

The bash script looks as follows:

#!/bin/bash

# -------------------------------
# A small script to utilize watch
# and pandoc on Windows, together
# with livereload
# -------------------------------


# infinite loop with while true
while true; 
  do pandoc $1 -f markdown -t html5 --self-contained -c github.css --highlight-style haddock -o index.html; 
  sleep 10; 
done &

# start a local webserver with livereload
livereload . -p 9000

It works by issuing the command bash panda-win.sh document.md, where panda-win.sh is the name of this bash script and document.md is the target document. The output is index.html, which is seen by the livereload.

Every 10 seconds, the whole thing reloads by itself instead of watching for changes.

getting pip3 on Windows

Since livereload is a python package, I had to install it through pip3. The cygwin installation comes with python3 and python2, but either version of pip was not installed.

I installed pip3 by first download the get-pip.py from https://bootstrap.pypa.io/get-pip.py, then I issued the command python3 get-pip.py, which then installed pip3.

This solution works for now. If anyone has any experience using file-watcher on Windows 10, let me know by tweeting me on Twitter (@aixnr). Thanks!

The next adventure is crafting a good-looking CSS for academic writing, with Tufte’s style being the inspiration.