Skip to content

Instantly share code, notes, and snippets.

@derek
Last active December 19, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derek/6002636 to your computer and use it in GitHub Desktop.
Save derek/6002636 to your computer and use it in GitHub Desktop.

Walkdown

Walks a directory looking for Markdown files and converts them to HTML.

Installing

$ git clone https://gist.github.com/6002636.git
$ cd 6002636
$ sudo npm install -g

Using

$ walkdown [source directory] [output directory]

Credits

Dedicated to @evangoer. You should go buy his YUI 3 Cookbook!

#!/usr/bin/env node
var glob = require("glob"),
markdown = require( "markdown" ).markdown,
path = require("path"),
fs = require("fs"),
mkdirp = require("mkdirp"),
indir = process.argv[2],
outdir = process.argv[3];
glob(indir + '/**/*.md', function (er, files) {
files.forEach(function(file){
var infile = file,
outfile = infile.replace(indir, outdir).replace(/md$/, 'html'),
output = markdown.toHTML(fs.readFileSync(infile, 'utf-8'));
mkdirp.sync(path.dirname(outfile));
fs.writeFileSync(outfile, output);
});
});
{
"name": "walkdown",
"dependencies": {
"glob": "3.2.x",
"markdown": "0.4.0",
"mkdirp": "0.3.x"
},
"bin": {
"walkdown": "./index.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment