Skip to content

Instantly share code, notes, and snippets.

@lumin3000
Created February 9, 2012 04:02
Show Gist options
  • Select an option

  • Save lumin3000/1777181 to your computer and use it in GitHub Desktop.

Select an option

Save lumin3000/1777181 to your computer and use it in GitHub Desktop.
markdown wathcer
###
Purpose:
Print web preview in lynx when the markdown file edited.
System requirement:
brew install markdown
brew install lynx
Usage:
coffee watcher.coffee path/to/x.markdown
###
util = require("util")
fs = require "fs"
spawn = require("child_process").spawn
args = process.argv.splice(2)+''
preview = (next)->
md = spawn("markdown", [ args ])
lynx = spawn("lynx" , ["--dump", "-assume_charset=utf-8", "-stdin" ])
md.stdout.on "data", (data) ->
lynx.stdin.write data
md.stderr.on "data", (data) ->
console.log "markdown stderr: " + data
md.on "exit", (code) ->
console.log "markdown process exited with code " + code if code isnt 0
lynx.stdin.end()
lynx.stdout.on "data", (data) ->
console.log data.toString()
lynx.stderr.on "data", (data) ->
console.log "lynx stderr: " + data
lynx.on "exit", (code) ->
console.log "lynx process exited with code " + code if code isnt 0
next()
watcher = ()->
console.log "####### watcher is running ########\n\n"
fs.watchFile args,()->
fs.unwatchFile args
preview(watcher)
watcher()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment