Skip to content

Instantly share code, notes, and snippets.

@Crisfole
Created February 15, 2013 15:04
Show Gist options
  • Select an option

  • Save Crisfole/4960896 to your computer and use it in GitHub Desktop.

Select an option

Save Crisfole/4960896 to your computer and use it in GitHub Desktop.
Very simple way to make a command line markdown renderer using Node.js and Pagedown. Only accepts streams in, not arguments, not files...Handy for langauges with a Popen3 library (write to the stdin, read from the stdout). Needed this so I could use the same library server side (rails) as client side. And because I was too lazy to try and figure…
function createMarkdown() {
var pagedown = require('pagedown');
var converter = new pagedown.getSanitizingConverter();
process.stdout.write(converter.makeHtml(lines));
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = "";
process.stdin.on('data', function(chunk) {
lines += chunk;
});
process.stdin.on('end', createMarkdown);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment